9

前回ファイルにアクセスしたときに取得したいので、次のコードを試してみました。

import os, time

os.system("python test.py")
print os.stat('test.py').st_atime

time.sleep(60)

os.system("python test.py")
print os.stat('test.py').st_atime

ただし、毎回出力は次のようになります。

1358489344.72
1358489344.72

遅延前と遅延後の出力の違いを期待していました。また、毎回コードを実行しても出力は同じです。

何が間違っている可能性がありますか?

4

2 に答える 2

7

フィールド st_atime は、ファイル アクセスによって変更されます。たとえば、execve(2)、mknod(2)、pipe(2)、utime(2)、および read(2) (0 バイト以上) によって変更されます。mmap(2) などの他のルーチンは、st_atime を更新する場合と更新しない場合があります。

"python test.py" を実行すると、read(2) は呼び出されず、代わりに mmap(2) が呼び出されます。そのため、アクセス時間は更新されませんでした。

「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
于 2013-01-18T07:08:21.127 に答える
1

ファイルシステムがnoatimeオプションでマウントされている可能性があります

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

あなたのチェック/etc/fstab

アクセス時間の詳細https://superuser.com/questions/464290/why-is-cat-not-ching-the-access-time

于 2013-01-18T06:56:21.410 に答える