/* should detect a problem in settimeofday * we set the time to the time we've just got * then we read the time, we should obtain a time just little bit after what we set * You need to be root to run this test */ #include #include #include #define USEC_PER_SEC 1000000 #define timerdiff(a,b) ((float)((a)->tv_sec - (b)->tv_sec) + \ (float)((a)->tv_usec - (b)->tv_usec)/USEC_PER_SEC) main() { struct timeval treq, tnew; float diff; // raise(SIGSTOP); /* do the test */ gettimeofday(&treq, NULL); settimeofday(&treq, NULL); gettimeofday(&tnew, NULL); /* interpret the result */ diff = timerdiff(&tnew, &treq); printf("requested:\t%lds %ldns\n" "new:\t\t%lds %ldns\n" "diff is %12.9fsec\n", treq.tv_sec, treq.tv_usec, tnew.tv_sec, tnew.tv_usec, diff); }