在Ubuntu 12.04 LTS下面的代碼:ntp_gettime()實際上是否返回納秒精度?
#include <stdio.h>
#include <sys/timex.h>
#include <sys/time.h>
int main(int argc, char **argv)
{
struct timeval tv;
gettimeofday(&tv, NULL);
struct ntptimeval ntptv;
ntp_gettime(&ntptv);
printf("gettimeofday: tv_sec = %ld, tv_usec = %ld\n",
tv.tv_sec, tv.tv_usec);
printf("ntp_gettime: tv_sec = %ld, tv_usec = %ld\n",
ntptv.time.tv_sec, ntptv.time.tv_usec);
}
回報:
gettimeofday: tv_sec = 1366209548, tv_usec = 137736
ntp_gettime: tv_sec = 1366209548, tv_usec = 137743081
這是一種奇怪的,因爲tv_usec
價值,如果它確實是微秒計,應不超過100萬更大。上面顯示的結果讓我認爲ntp_gettime()
實際上返回納秒精度。
ntp_gettime()
聯機幫助頁(確切地說)在http://manpages.ubuntu.com/manpages/precise/man2/ntp_gettime.2freebsd.html 並沒有真正說太多。
較早的聯機幫助版本(代) http://manpages.ubuntu.com/manpages/hardy/man2/ntp_gettime.2.html索賠它可能是依賴於STA_NANO
位是否被通過ntp_adjtime()
返回status
詞集要麼納秒或微秒。
任何人都知道明確嗎?短缺的是,ntp_gettime()
,ntp_adjtime()
以及它們在12.04源代碼中定義的所有各種內部函數在哪裏?