gpt4 book ai didi

linux - 获取文件的纳秒精度 atime、mtime、ctime 字段(stat?)

转载 作者:IT王子 更新时间:2023-10-28 23:54:36 28 4
gpt4 key购买 nike

一些文件系统(例如 ext4 和 JFS)提供纳秒分辨率的 atime/mtime 字段。如何读取 ns 分辨率字段? 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 */

可是“NOTES”节的人http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html说:

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

关于linux - 获取文件的纳秒精度 atime、mtime、ctime 字段(stat?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7206014/

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