- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <signal.h>
- #include <sys/time.h>
- void Demo_updateTime(int signo)
- {
- printf("timer comer.\n");
- }
- int main(int argc, char *argv[])
- {
- struct itimerval oneSec;
- signal(SIGALRM, Demo_updateTime);
- oneSec.it_value.tv_sec = 1;
- oneSec.it_value.tv_usec = 0;
- oneSec.it_interval.tv_sec = 1;
- oneSec.it_interval.tv_usec = 0;
- setitimer(ITIMER_REAL, &oneSec, NULL);
- while(1)
- sleep(9999);
- }
去掉while(1)这一行只执行一次定时器;不解释。
阅读(866) | 评论(0) | 转发(0) |