C, clock_gettime, returned incorrect nanosecond value?

后端 未结 2 384
傲寒
傲寒 2021-01-23 09:49

I\'m writing a simple program, which checks if elapsed time is more than 1 seconds. I take start time with a clock_gettime(), then I call sleep(5), take new time and I check if

2条回答
  •  不思量自难忘°
    2021-01-23 10:39

    You are using the nsec (nanoseconds) portion of the timestamps and totally ignoring the sec (seconds) part. Those timestamps are composed of two integers, and to get any meaning from them you need both.

    Ref: http://en.cppreference.com/w/c/chrono/timespec

提交回复
热议问题