在linux C编程中,定时器函数选择与设置问题
在linux中C编程中,有ABCDEF六个事件需要在一个线程中按顺序处理,每个事件处理完成后,需定时一段时间,这段时间里线程睡眠挂起,等待定时时间到,线程被唤醒再处理下一...
在linux中 C编程中,有ABCDEF六个事件需要在一个线程中按顺序处理,每个事件处理完成后,需定时一段时间,这段时间里线程睡眠挂起,等待定时时间到,线程被唤醒再处理下一个事件;各个事件间的定时时间不同;而且比如有时候需要在处理事件A后,时间定时未到、线程睡眠期间,立即唤醒线程,跳到处理事件E。事件E处理完后,按正常的顺序处理剩下的事件。请问使用哪种定时器函数,能否很好的实现这样的功能?
展开
2个回答
展开全部
试试alarm()与signal(),例子铅神可以槐坦亏网上搜搜
NAME
alarm - set an alarm clock for delivery of a signal
SYNOPSIS
#include <unistd.h>信宴
unsigned int alarm(unsigned int seconds);
DESCRIPTION
alarm() arranges for a SIGALRM signal to be delivered to the calling process in seconds seconds.
If seconds is zero, no new alarm() is scheduled.
In any event any previously set alarm() is canceled.
NAME
alarm - set an alarm clock for delivery of a signal
SYNOPSIS
#include <unistd.h>信宴
unsigned int alarm(unsigned int seconds);
DESCRIPTION
alarm() arranges for a SIGALRM signal to be delivered to the calling process in seconds seconds.
If seconds is zero, no new alarm() is scheduled.
In any event any previously set alarm() is canceled.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询