<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>
setitmer() linux 下的精确定时函数
最新推荐文章于 2024-07-14 22:55:16 发布