Linux 下setitimer函数的使用
来源:互联网 发布:美国大学统计 知乎 编辑:程序博客网 时间:2024/06/05 09:42
在编程的时候,很多时候会用到定时器,定时检测某个状态是否发生变化并进行处理。这时候,就会用到setitimer函数了。
1. 要使用setitimer函数,要包含头文件:#include <sys/time.h>
2. 该函数的原型是:int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value);
3. 参数:
(1)int which:为以下的一种
ITIMER_REAL:decrements in real time, and deliversSIGALRM upon expiration.
ITIMER_VIRTUAL:decrements only when the process is executing, anddeliversSIGVTALRM upon expiration.
ITIMER_PROF:decrements both when the process executes and when the system is executing on behalf
of the process. Coupledwith ITIMER_VIRTUAL, this timer is usually used to profile the time
spent by the application in user and kernel space. SIGPROF is delivered
(2)struct itimerval *new_value,其定义如下:
其中it_value表示设置定时器后间隔多久开始执行定时任务,而it_interval表示两次定时任务之间的时间间隔。
(3)上一次定时器的值,一般置为NULL即可
4. 返回值:成功返回0;失败返回-1,并把错误号写到errno变量中
5. 以下是使用的简单实例(ITIMER_REAL,其他的类似)
- Linux 下setitimer函数的使用
- Linux 下setitimer函数的使用
- Linux 下setitimer函数的使用
- linux下的定时器函数setitimer()
- linux下定时器的使用 - alarm() & setitimer()
- linux下定时器setitimer的使用
- Linux下定时函数setitimer
- Linux下定时函数setitimer
- linux下定时器函数 setitimer()
- Linux下定时函数setitimer
- Linux下使用setitimer函数实现多个定时器的功能
- linux上定时函数 setitimer 的使用介绍
- linux上定时函数 setitimer 的使用介绍
- Linux应用层下定时器函数setitimer
- Linux下的定时器:alarm()与setitimer()
- Linux下的定时器:alarm()与setitimer()
- Linux下的定时器:alarm()与setitimer()
- Linux下的定时器:alarm()与setitimer()
- ThinkPHP5.0-数据库
- (转)非对称加密,我终于理解了!
- SIGPIPE信号
- T_REP_REQ
- PID连续控制算法的表达式以及C语言实现
- Linux 下setitimer函数的使用
- C# MVC Html.DropDownList htmlAttributes 增加 data_options
- Java File类用法详解
- androidstudio 如何从svn服务器down项目
- 有趣的autolayout例子
- PES分组字段(table)
- ThreadLocal的一些猫腻
- Maven学习总结(13)——深入理解maven灵活的构建
- MVP模式的基本使用