How to use timer in Linux C language
Write a program (library) to realize the function of timer (timer), which can provide users with timers used many times in the same process. Here, it is required to be realized by signal. The sample code is as follows: # include # include static int time_count = 0; static struct itimerval oldtv; void set_timer () {struct itimerval itv; itv.it_interval.tv_sec = 1; itv.it_interval.tv_usec = 0; itv.it_value.tv_sec = 1; itv.it_value.tv_usec = 0 Setitimer (ITIMER_REAL, & itv, & oldtv);} void signal_handler (int m) {time_count + +; printf ("% d\ n", time_count);} int main () {signal (SIGALRM, signal_handler); set_timer (); while (1) {if (time_count==5) {printf ("time_count= 5\ n") Time_count=0;}} return 1;}