我有一個非常簡單的代碼運行在Linux上,如下圖所示:clock_gettime返回一些非常大的價值
struct timespec SysTime_Test;
#define BILLION 1000000000L
SysTime_Test.tv_sec = 0;
SysTime_Test.tv_nsec = 0;
clock_settime(CLOCK_REALTIME,&SysTime_Test);
while(1) {
printf("%d ",clock_gettime(CLOCK_REALTIME,&SysTime_Test));
printf("%llu, %llu\n",SysTime_Test.tv_sec, SysTime_Test.tv_nsec);
fflush(stdout);
}
而且我期待着開始:
0 0, 0
,而不是我的了:
0 97508642543791, 13184898790915571716
0 152071907084879, 13184898790915571716
0 184202557433736, 13184898790915571716
0 214744069882703, 13184898790915571716
............
0 688307164049923, 13184898790915571716
0 715983933311791, 13184898790915571716
0 743664997540956, 13184898790915571716
0 770706111642868, 13184898790915571716
0 798223967114747, 13184898790915571716
0 825746117553923, 13184898790915571716
0 853263973025802, 13184898790915571716
0 881898519994901, 13184898790915571716
0 909098547886802, 13184898790915571716
0 936779612115967, 13184898790915571716
0 964138553797857, 13184898790915571716
0 992455273186978, 13184898790915571716
0 1019973128658857, 13184898790915571716
0 1048130934257989, 13184898790915571716
..........
0 1318713873968989, 13184898790915571716
0 1346549557020846, 13184898790915571716
0 1374707362619978, 13184898790915571716
0 1402225218091857, 13184898790915571716
0 1430700851270967, 13184898790915571716
..........
0 2643470766924857, 13184898790915571716
0 2670988622396736, 13184898790915571716
0 2698828600415890, 13184898790915571716
0 2726187542097780, 13184898790915571716
0 2754027520116934, 13184898790915571716
0 2781704289378802, 13184898790915571716
0 2809544267397956, 13184898790915571716
0 2836903209079846, 13184898790915571716 (Big jump)
0 1434656352942746714, 13184898790915571716
0 1434694848734629725, 13184898790915571716
..................
0 1435769544041619659, 13184898790915571716
0 1435796907278268846, 13184898790915571716
0 1435824266219950736, 13184898790915571716
我已經嘗試過不同的時鐘ID,我仍然有幾乎相同的事情,有一個大跳之間,我有什麼做錯了?
什麼'clock_settime'返回?! –
此外,這是**整個**程序?你是否包含'stdio.h'?你是否得到了關於'printf'錯誤參數的警告,你是否正確地編譯了程序? –
I.e.這*不是* [mcve] –