#include #include #include #include #include #include bool gotit = false; void timer_handler(int sig) { int ret_val; gotit = true; printf("Timer expired\n"); } int main() { signal(SIGVTALRM, timer_handler); struct itimerval tv; tv.it_value.tv_sec = 2; //time of first timer tv.it_value.tv_usec = 0; //time of first timer tv.it_interval.tv_sec = 2; //time of all timers but the first one tv.it_interval.tv_usec = 0; //time of all timers but the first one setitimer(ITIMER_VIRTUAL, &tv, NULL); for(; ;) { if (gotit) { printf("Got it!\n"); gotit = false; } } return 0; }