当前位置: 技术问答>linux和unix
Linux下timer问题
来源: 互联网 发布时间:2015-11-30
本文导语: UINT TimerClockSignal(VOID) { struct itimerval itimer; if (signal(SIGALRM, &ipGchAlarmHandler) == SIG_ERR) { LogCall(LOG_ERROR, "Couldn't register signal handler for SIGALRM.n"); } itimer.it_interval.tv_usec = vg_iTickBase; itimer.it_interval.tv_sec = 0; ...
UINT TimerClockSignal(VOID)
{
struct itimerval itimer;
if (signal(SIGALRM, &ipGchAlarmHandler) == SIG_ERR)
{
LogCall(LOG_ERROR, "Couldn't register signal handler for SIGALRM.n");
}
itimer.it_interval.tv_usec = vg_iTickBase;
itimer.it_interval.tv_sec = 0;
itimer.it_value.tv_usec = vg_iTickBase;
itimer.it_value.tv_sec = 0;
setitimer(ITIMER_REAL, &itimer, NULL);
LogCall(LOG_BASIC, "***begin soft tick alarm[v=%d]****n", vg_iTickBase);
return 0;
}
我用这个函数实现一个软定时器,问题是启动了这个后,我的进程的select函数就无法正确触发.
有什么原因么?
{
struct itimerval itimer;
if (signal(SIGALRM, &ipGchAlarmHandler) == SIG_ERR)
{
LogCall(LOG_ERROR, "Couldn't register signal handler for SIGALRM.n");
}
itimer.it_interval.tv_usec = vg_iTickBase;
itimer.it_interval.tv_sec = 0;
itimer.it_value.tv_usec = vg_iTickBase;
itimer.it_value.tv_sec = 0;
setitimer(ITIMER_REAL, &itimer, NULL);
LogCall(LOG_BASIC, "***begin soft tick alarm[v=%d]****n", vg_iTickBase);
return 0;
}
我用这个函数实现一个软定时器,问题是启动了这个后,我的进程的select函数就无法正确触发.
有什么原因么?
|
select函数被signal中断了,要是select的返回值为-1要判断errno是否为EINTR,如果是的话就继续select