Re: [問題] 關於 file time
嗯 我最近找到可能的解釋方式了
事實上 當我去
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
推
05/30 15:38, , 1F
05/30 15:38, 1F
推
05/30 17:34, , 2F
05/30 17:34, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 5 篇):
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章