linux c++(信号处理 & 定时发送信号)

定时给自己发送SIGALRM
几秒后发送信号
返回值,上次闹钟剩余的秒数
特别的,如果传入参数为0,代表取消闹钟
#include <unistd.h>
unsigned int alarm(unsigned int seconds);


settimer函数,周期性的发送信号
struct itimerval{
	struct timeval it_interval; //周期性的时间设置
	struct timeval it_value;	//下次的闹钟时间
};
struct timeval{
	time_t tv_sec;  //秒
	suseconds_t tv_usec; //微秒
 }

which:
	ITIMER_REAL 自然定时法 SIGALRM
	ITIMER_VIRTUAL 计算进程执行时间 SIGVTALRM
	ITIMER_PROF	进程执行时间+调度时间 SIGPROF
new_val		要设置的闹钟时间
old_val		原闹钟时间
	
int getitimer(int which, struct itimerval *curr_value);
int setitimer(int which, const struct itimerval *new_value,struct itimerval *old_value);

posted on 2021-05-05 23:08  lodger47  阅读(392)  评论(0)    收藏  举报

导航