采样的时候要用到定时器,定时的进行采样。这时候,就会用到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.
以系统真实的时间来计算,它送出SIGALRM信号。
ITIMER_VIRTUAL:decrements only when the process is executing, anddeliversSIGVTALRM upon expiration.
以该进程在用户态下花费的时间来计算,它送出SIGV