#include #include #include #include #include static struct { const int timer_type; const int signal; volatile sig_atomic_t count; } timer_tests[] = { /* from slowest to fastest */ { ITIMER_VIRTUAL, SIGVTALRM }, { ITIMER_PROF, SIGPROF }, { ITIMER_REAL, SIGALRM }, }; static int count; static void timer_tick(int sig) { count++; } int main() { struct itimerval tv = { .it_interval = { .tv_sec = 0, .tv_usec = 100000 }, .it_value = { .tv_sec = 0, .tv_usec = 100 }, }; int i = 0; time_t start; if (signal(timer_tests[i].signal, timer_tick) == SIG_ERR) exit(1); if (setitimer(timer_tests[i].timer_type, &tv, NULL) < 0) exit(1); start = time(NULL); for (;;) if (time(NULL) - start > 10) break; return 0; }