Get last access time of the file?

馋奶兔 提交于 2019-11-29 06:57:19

The field st_atime is changed by file accesses, for example, by execve(2), mknod(2), pipe(2), utime(2) and read(2) (of more than zero bytes). Other routines, like mmap(2), may or may not update st_atime.

While you run "python test.py", it won't call read(2), instead it would call mmap(2). That's why the access time didn't be udpated.

Here is output of "strace python test.py"

open("test.py", O_RDONLY)               = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=36, ...}) = 0
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ad626cdd000
freestyler

Maybe the filesystem is mounted with noatime option

noatime
     Do not update inode access times on this filesystem 
     (e.g, for faster access on the news spool to speed up news servers).

check your /etc/fstab

More about access time https://superuser.com/questions/464290/why-is-cat-not-changing-the-access-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!