C, clock_gettime, returned incorrect nanosecond value?
问题 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 the difference is bigger than 1; I sleep 5 seconds, then it should be greater than 5, but my program prints a strange result. this is the code: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> int main() { struct timespec tv1,tv3,expected; struct timespec nano1; tv1.tv_nsec = 0; tv3.tv_nsec =