python file read  with strace 
    cat file_ro.py 
    import sys
    def file_open(filename):
    		fo=open(filename,'r')
    		fo.seek(7)
    		read_data=fo.read(3)
    		fo.close()
    		print read_data
    file_open("file.py")


But strace says 





    readlink("file_ro.py", 0x7fff31fc7ea0, 4096) = -1 EINVAL (Invalid argument)
    getcwd("/home/laks/python", 4096)       = 18
    lstat("/home/laks/python/file_ro.py", {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    stat("file_ro.py", {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    open("file_ro.py", O_RDONLY)            = 3
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    lseek(3, 0, SEEK_SET)                   = 0
    read(3, "import sys\ndef file_open(filenam"..., 128) = 128
    read(3, "ile_open(\"file.py\")\n\t\n", 4096) = 22
    close(3)                                = 0
    munmap(0x7fa671a6c000, 4096)            = 0
    stat("file_ro.py", {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    open("file_ro.py", O_RDONLY)            = 3
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff31fc9e30) = -1 ENOTTY (Inappropriate ioctl for device)
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    lseek(3, 0, SEEK_CUR)                   = 0
    read(3, "import sys\ndef file_open(filenam"..., 4096) = 150
    lseek(3, 150, SEEK_SET)                 = 150
    read(3, "", 4096)                       = 0
    close(3)                                = 0
    munmap(0x7fa671a6c000, 4096)            = 0
    open("file.py", O_RDONLY)               = 3
    fstat(3, {st_mode=S_IFREG|0755, st_size=305, ...}) = 0
    fstat(3, {st_mode=S_IFREG|0755, st_size=305, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    lseek(3, 0, SEEK_SET)                   = 0
    read(3, "import ", 7)                   = 7
    read(3, "sys\ndef file_open(filename):\n\t\"\""..., 4096) = 298
    close(3)                                = 0
    munmap(0x7fa671a6c000, 4096)            = 0
    fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    write(1, "sys\n", 4sys
    )                    = 4
    rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x306140efa0}, {0x306d10b2b0, [], SA_RESTORER, 0x306140efa0}, 8) = 0
    close(5)                                = 0
    munmap(0x7fa671952000, 4096)            = 0
    exit_group(0)  


As you can see above - 

read(3, "import sys\ndef file_open(filenam"..., 4096) = 150

Why read() returns 150 bytes when the program says to read only 3 bytes ?



python file read  with strace 
===

    cat file_ro.py 
    import sys
    def file_open(filename):
    		fo=open(filename,'r')
    		fo.seek(7)
    		read_data=fo.read(3)
    		fo.close()
    		print read_data
    file_open("file.py")


But strace says 





    readlink("file_ro.py", 0x7fff31fc7ea0, 4096) = -1 EINVAL (Invalid argument)
    getcwd("/home/laks/python", 4096)       = 18
    lstat("/home/laks/python/file_ro.py", {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    stat("file_ro.py", {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    open("file_ro.py", O_RDONLY)            = 3
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    lseek(3, 0, SEEK_SET)                   = 0
    read(3, "import sys\ndef file_open(filenam"..., 128) = 128
    read(3, "ile_open(\"file.py\")\n\t\n", 4096) = 22
    close(3)                                = 0
    munmap(0x7fa671a6c000, 4096)            = 0
    stat("file_ro.py", {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    open("file_ro.py", O_RDONLY)            = 3
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff31fc9e30) = -1 ENOTTY (Inappropriate ioctl for device)
    fstat(3, {st_mode=S_IFREG|0755, st_size=150, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    lseek(3, 0, SEEK_CUR)                   = 0
    read(3, "import sys\ndef file_open(filenam"..., 4096) = 150
    lseek(3, 150, SEEK_SET)                 = 150
    read(3, "", 4096)                       = 0
    close(3)                                = 0
    munmap(0x7fa671a6c000, 4096)            = 0
    open("file.py", O_RDONLY)               = 3
    fstat(3, {st_mode=S_IFREG|0755, st_size=305, ...}) = 0
    fstat(3, {st_mode=S_IFREG|0755, st_size=305, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    lseek(3, 0, SEEK_SET)                   = 0
    read(3, "import ", 7)                   = 7
    read(3, "sys\ndef file_open(filename):\n\t\"\""..., 4096) = 298
    close(3)                                = 0
    munmap(0x7fa671a6c000, 4096)            = 0
    fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa671a6c000
    write(1, "sys\n", 4sys
    )                    = 4
    rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x306140efa0}, {0x306d10b2b0, [], SA_RESTORER, 0x306140efa0}, 8) = 0
    close(5)                                = 0
    munmap(0x7fa671952000, 4096)            = 0
    exit_group(0)  


As you can see above - 

read(3, "import sys\ndef file_open(filenam"..., 4096) = 150

Why read() returns 150 bytes when the program says to read only 3 bytes ?


