gpt4 book ai didi

unix - 文件创建/打开对 st_mtime 和 st_atime 的影响

转载 作者:行者123 更新时间:2023-12-02 13:53:47 31 4
gpt4 key购买 nike

当我使用 O_CREAT 标志在 UNIX 中创建或打开文件时,st_mtimest_ctimest_atime文件发生变化。但是,当我使用 O_TRUNC 标志创建或打开文件时,只有 st_mtimest_ctime 更改,而不是 st_atime .

根据我的理解,st_atime 在访问文件时会发生变化。当我们使用 O_TRUNcflags打开或创建文件时,我们是否没有访问该文件?

最佳答案

这个问题有点老了,但至少为后代提供了答案......

来自 stat(2) 手册页(在具有 Linux 2.6.32 内核的主机上):

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.

The field st_mtime is changed by file modifications, for example, by mknod(2), truncate(2), utime(2) and write(2) (of more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.

The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).

关于unix - 文件创建/打开对 st_mtime 和 st_atime 的影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5631192/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com