首页 > 编程语言 > 详细

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

时间:2021-05-06 09:28:55      阅读:23      评论:0      收藏:0      [点我收藏+]
定时给自己发送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);

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

原文:https://www.cnblogs.com/lodger47/p/14733294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!