当调用clock_gettime()时,返回的tv_nsec字段实际上可能超过一秒钟吗? [英] When invoking clock_gettime() may the returned tv_nsec field actually exceed a second?
问题描述
当您调用clock_gettime()
时,它将返回一个timespec结构.
When you invoke clock_gettime()
it returns a timespec structure.
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
我在手册页中没有找到tv_nsec不会超过一秒的保证.保证金实际上存在吗?是否可以依赖于Linux的库(glibc?)实现?
I don't find in the man page a garantee that the tv_nsec won't exceed one second. Does the garantee exist actually ? Could it be dependant on the library (glibc?) implementation for linux?
关键思想是:我是否需要对来自clock_gettime()
函数的结果进行归一化"?
The key idea is : do I need to 'normalize' any result coming from the clock_gettime()
function?
推荐答案
根据公开组
tv_nsec成员仅在大于或等于零时才有效,并且 小于每秒的纳秒数(十亿).这 此结构描述的时间间隔为(tv_sec * 10'-.4m'9'.4m' + tv_nsec)纳秒.
The tv_nsec member is only valid if greater than or equal to zero, and less than the number of nanoseconds in a second (1000 million). The time interval described by this structure is (tv_sec * 10'-.4m'9'.4m' + tv_nsec) nanoseconds.
因此,根据opengroup,官方认为它必须少于1秒.
So according to opengroup, it looks official that it must be less than 1 second.
这篇关于当调用clock_gettime()时,返回的tv_nsec字段实际上可能超过一秒钟吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!