作者coo1be (我不会开卡丁车啦)
看板LinuxDev
标题Re: [问题] 关於 file time
时间Wed May 30 15:27:00 2007
嗯 我最近找到可能的解释方式了
事实上 当我去
1) 以 vim 打开一个档案
2) 以 cp 复制一个档案
以上这两个动作 其实会改动到 st_atime
但是为什麽之前会发生 st_atime 没有改变的情形呢
以下是我自己推测的原因
很有可能是 我在短时间之内 对同一个档案做了很多 operation
APUE 中 并没有特别提到说 access 到 file 的什麽东西 才会改动 st_atime
(很有可能是去access file 的 i-node)
如果说 OS 有做 i-node 的 cache, 那麽以上就可以说得通了
因为当我再度的想 access 该档案的时候 并不用再度去 file 的 i-node 得到
档案在硬碟的哪个地方 而是可以直接从 i-node cache 中得到档案的所在资讯
因此 也就不会 access 到 file 的 i-node 更不会 updata st_atime 了
以上的想法 会依不同的 OS 设计 有不同的结果
如果 OS 不做 i-node cache 那 st_atime 不被动到 就真的蛮奇怪的
※ 引述《wlsabcd ()》之铭言:
: ※ 引述《KvsG (KvsG)》之铭言:
: : 我那时写这程式也有同样的问题... 不过後来我找到原因了...
: : CreateTime & ModifyTime 很容易理解吧... AccessTime 跟我们的认知却不一样...
: : Access 我们会以为是去读取的时间... 其实不是...
: : Access 的意思是有去"动到 i-node 的时间" ...
: : 所以你一直打开 执行 复制... aTime是不会变的...
: : 你去 chmod chown ... aTime 就会变了...
: : 印象中是这样啦.. ^^" 那时写 stat 的测试程式不知跑哪去了没得试...
: : 如果不对请指正 ^^"
: : 如果你是想知道一个档最後一次被读取/执行的时间的话...
: : 说真的我也不知道... 找到资料的话交流一下吧... XD
: 翻了一下APUE 第一版 (Chapter 4.18, 4.19) 里面有很详细的解释,
: (之前没用到都忘光了,感谢各位的发问让我有复习的机会)
: 这本书年代已经很久远了,但也应该不会错
: File 的时间,可分为 st_atime, st_mtime, st_ctime
: st_atime: last-access time of file data
: 档案内容最後被读取的时间,可由 ls -lu 观察到
: st_mtime: last-modification time of the file data
: 档案内容最後被更改/读取的时间,可由 ls -l 观察到
: st_ctime: last-change time of i-node status
: i-node 最後被修改的时间,可由 ls -lc 观察到
: 这三的资料结构可以由 stat, fstat, lstat system call 得到。
: 所以C大、K大的问题,知道档案最後读取时间,可由 ls - lu 命令,
: 或者由程式中呼叫 stat, fstat, lstat 观察到。
: ========================================================================
: 另外,哪些 function 会更改这三个资料结构的的内容,以下列表
: Funtion Referenced file Parent directly Note
: of referenced file
: ---------------- -------------------
: a m c a m c
: ---------------- -------------------
: chmod, fchmod Y
: chown, fchown Y
: creat Y Y Y Y Y O_CREAT new file
: creat Y Y O_TRUNC existing file
: exec Y
: lchown Y
: link Y Y Y
: mkdir Y Y Y Y Y
: mkfifo Y Y Y Y Y
: open Y Y Y Y Y O_CREAT new file
: open Y Y O_TRUNC existing file
: pipe Y Y Y
: read Y
: remove Y Y Y remove file = unlink
: remove Y Y remove directly = rmdir
: rename Y Y Y for both arguments
: rmdir Y Y
: truncate,ftruncate Y Y
: unlink Y Y Y
: utime Y Y Y
: write Y Y
: ===============================================================================
: 还有直接修改 st_atime, st_mtime 的 system call: utime
: ===============================================================================
: 以上,和各位先进交流
: ref: Advanced Programming in the UNIX Environment, 1st Edition
: W. Richard Stevens
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.37
1F:推 KENyroj:PUSH! 我们那时好像也有这个结论 XDXD 05/30 15:38
2F:推 wlsabcd:果然读万卷书,不如行万里路;回去试看看 :) 05/30 17:34