2014-02-14 1 views
1

man 2 statstruct stat에 반환 된 st_atime, st_mtime 및값이 초 단위 해상도 인 time_t임을 보여줍니다. 더 높은 해상도에서 같은 값을 얻는 방법, 아마도 struct timespec 또는 struct timeval 또는 누락 된 하위 초 부분?최대 해상도로 파일 타임 스탬프를받는 방법은 무엇입니까?

Linux에서 C++에이 작업이 필요하지만 C로 태그를 지정하는 이유는 아마도 두 언어 모두에서 대답이 동일 할 것이기 때문입니다. man 2 stat의 참고 섹션에 따르면

답변

2

:

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. On file systems that do not support subsecond timestamps, the nanosecond fields are 
    returned with the value 0. 
+0

한 가지가 나노초 해상도 경우에도 염두에 두어야은 당신 수도 하드웨어에 아무런 가져 오기 나노초 정도. 예를 들어, 일반적인 인텔 하드웨어는 약 1 밀리 초 정도의 정확도를 유지하므로 많은 나노초의 가치를 얻을 수는 있지만 일반적으로 1 밀리 초 미만은 신뢰할 수 없습니다. – jia103

관련 문제