Notes:
Delays in Linux applications such as the Sleep (), Msleep (), and Usleep () functions also have the following form of delay:
struct Timeval delay; Delay.tv_sec = Sleepsecond; delay.tv_usec = 0; Select (0, NULL, NULL, NULL, &delay);
But basically is based on the process of sleep, as if there is no cycle waiting delay, to be confirmed, not found at present.
Considering a problem, if the signal is sent on a timed basis, the function is executed when the corresponding signal processing function is executed, and another signal comes again, how to deal with it? The answer is to wait for the previous signal processing to complete.
The timer is used in conjunction with the KILL function to satisfy certain special requirements for immediate execution and periodic execution of the corresponding function, as follows:
/********************************************************************************* * Copyright: (C) EAST * All rights reserved. * * FILENAME:SETITIMER.C * description:this file * * version:1.0.0 (08/08/2014) * Author:fulinux <[email protected]> * changelog:1, Release initial version on "08/08/2014 12:58: "* ********************************************************************************/#include <st dio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <time.h># Include <sys/time.h>static int switch_val = 0;void sigroutine (int signo) {switch (signo) {case SIGALRM: printf ("Catch a signal--SIGALRM \ n"); Break Case sigvtalrm:printf ("Catch a signal-SIGVTALRM \ n"); Switch (switch_val) {case 0:printf ("switch_val = 0\n"); Break Case 1:printf ("switch_val = 1\n"); Break Case 2:printf ("switch_val = 2\n"); Break Case 3:printf ("switch_val = 3\n"); Break Default:return; } break; } return; int main () {struct Itimerval value, Ovalue, value2; (1) printf ("Process ID is%d\n", getpid ()); Signal (SIGALRM, sigroutine); Signal (SIGVTALRM, sigroutine); Value.it_value.tv_sec = 1; value.it_value.tv_usec = 0; Value.it_interval.tv_sec = 1; value.it_interval.tv_usec = 0; Setitimer (Itimer_real, &value, &ovalue); (2) value2.it_value.tv_sec = 0; Value2.it_value.tv_usec = 1; value2.it_interval.tv_sec = 0; Value2.it_interval.tv_usec = 500000; Setitimer (Itimer_virtual, &value2, &ovalue); #if 0 struct Timeval Delay delay.tv_sec = 0; Delay.tv_usec = 500000; Select (0, NULL, NULL, NULL, &delay); #endif switch_val = 1; Kill (Getpid (), SIGVTALRM); printf ("Fulinux 1\n"); Switch_val = 2; Kill (Getpid (), SIGVTALRM); printf ("Fulinux 2\n"); Switch_val = 3; Kill (Getpid (), SIGVTALRM); printf ("Fulinux 3\n"); for (;;) ;}