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

linux – 获取一个纳秒精确的atime,mtime,ctime字段的文件(stat

发布时间:2020-12-13 18:15:47 所属栏目:Linux 来源:网络整理
导读:一些文件系统(例如ext4和JFS)提供了atime / mtime字段的纳秒分辨率.如何读取ns-resolution字段? stat syscall返回time_t,这是第二分辨率. 解决方法 第二分辨率时间是在以下领域: time_t st_atime; /* time of last access */ time_t st_mtime; /* time of
一些文件系统(例如ext4和JFS)提供了atime / mtime字段的纳秒分辨率.如何读取ns-resolution字段? stat syscall返回time_t,这是第二分辨率.

解决方法

第二分辨率时间是在以下领域:
time_t    st_atime;   /* time of last access */
           time_t    st_mtime;   /* time of last modification */
           time_t    st_ctime;   /* time of last status change */

但是http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html的“NOTES”部分说:

Since kernel 2.5.48,the stat structure supports nanosecond resolution for the three file timestamp fields. Glibc exposes the nanosecond component of each
field using names of the form st_atim.tv_nsec if the _BSD_SOURCE or
_SVID_SOURCE feature test macro is defined. These fields are specified in
POSIX.1-2008,and,starting with version 2.12,glibc also exposes these field
names if _POSIX_C_SOURCE is defined with the value 200809L or greater,or
_XOPEN_SOURCE is defined with the value 700 or greater. If none of the
aforementioned macros are defined,then the nanosecond values are exposed with
names of the form st_atimensec.

所以,nsec部分的时间是相同的“struct stat”:(/usr/include/asm/stat.h)

unsigned long st_atime_nsec;

 unsigned int st_mtime_nsec;

 unsigned long st_ctime_nsec;

 #define STAT_HAVE_NSEC 1

(编辑:李大同)

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

    推荐文章
      热点阅读