I have a very simple code running on linux, as shown below:
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);
}
And I am expecting to start with:
0 0, 0
instead I got:
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
I have tried with different clock ID and I still got almost the same thing, with a big jump in between, what have I done wrong?