加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 21:03:23 所属栏目:安全 来源:网络整理
导读:当我使用O_CREAT标志在UNIX中创建或打开文件时,文件的st_mtime,st_ctime和st_atime会发生变化.但是当我使用O_TRUNC标志创建或打开文件时,只有st_mtime和st_ctime更改而不是st_atime. 根据我的理解,st_atime在访问文件时会发生变化.当我们使用O_TRUNC标志打开
当我使用O_CREAT标志在UNIX中创建或打开文件时,文件的st_mtime,st_ctime和st_atime会发生变化.但是当我使用O_TRUNC标志创建或打开文件时,只有st_mtime和st_ctime更改而不是st_atime.

根据我的理解,st_atime在访问文件时会发生变化.当我们使用O_TRUNC标志打开或创建文件时,我们是否不访问该文件?

解决方法

这个问题有点陈旧,但对后代至少是一个答案……

从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,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,link count,mode,etc.).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读