setitmer() linux 下的精确定时函数

来源:互联网 发布:centos如何启用双网卡 编辑:程序博客网 时间:2024/04/30 09:59
<span style="font-size:18px;">#include <stdio.h>#include <unistd.h>#include <time.h>#include <sys/time.h>#include <signal.h>void alrm_func(int sn);int main(int argc, char *argv[]){signal(SIGALRM, alrm_func);// 第一次在1.0 秒后,之后每0.5 秒发送一个SIGALRM 信号struct itimerval itimer = { {0, 500000}, {1, 0} };setitimer(ITIMER_REAL, &itimer, NULL);while (1)pause();return 0;}void alrm_func(int sn){time_t tm = time(NULL);printf("%s", ctime(&tm));}</span>

0 0
原创粉丝点击