C - setitimer ============= Public Domain ******************************************************************************** ### setitimer : set interval timer #include #include #include #include #include double count; void catcher(int signum) { static i = 1; if (signum == SIGALRM) { printf(" i = %05d , count = %.0f \n", i++, count); return; } else if (signum == SIGINT) { printf("\n SIGINT \n"); exit(EXIT_SUCCESS); } } int main() { struct itimerval tval; struct sigaction act; /* Catching SIGALRM and SIGINT */ memset(&act, 0, sizeof(act)); act.sa_handler = &catcher; sigaction(SIGALRM, &act, NULL); sigaction(SIGINT, &act, NULL); /* Timer kicks in after one microsecond */ tval.it_value.tv_sec = 0; tval.it_value.tv_usec = 1; /* Timer fires every three seconds */ tval.it_interval.tv_sec = 3; tval.it_interval.tv_usec = 0; /* Starting a timer to send the SIGALRM signal */ setitimer(ITIMER_REAL, &tval, NULL); /* Infinite addition */ for (count = 0; ;count++); return 0; } ******************************************************************************** _BY: Pejman Moghadam_ _TAG: c, setitimer, signal_ _DATE: 2014-01-19 01:39:14_