#include #include #include #include int main(int ac, char ** av) { struct timeval tv1, tv2; struct timespec ts, tr; unsigned int v = 8; if (av[1]) v = atoi(av[1]); printf("Sleeping %d ms\n", v); while (1) { tv2.tv_sec = 0; tv2.tv_usec = v * 1000; gettimeofday(&tv1, NULL); select(0, NULL, NULL, NULL, &tv2); gettimeofday(&tv2, NULL); printf("s %ld.%06ld - %ld.%06ld\n", tv1.tv_sec, tv1.tv_usec, tv2.tv_sec, tv2.tv_usec); sleep(1); ts.tv_sec = 0; ts.tv_nsec = v * 1000000; gettimeofday(&tv1, NULL); nanosleep(&ts, &tr); gettimeofday(&tv2, NULL); printf("n %ld.%06ld - %ld.%06ld\n", tv1.tv_sec, tv1.tv_usec, tv2.tv_sec, tv2.tv_usec); sleep(1); } return 0; }