学习笔记:
功能: 设置定时器(闹钟)。可代替alarm函数。精度为微妙us,可以实现周期定时。
参数:which 指定定时方式。
1)自然定时: ITIMER_REAL -> 14) SIGALRM
2)虚拟空间计时(用户空间): ITIMER_VIRTUAL -> 26) SIGVTALRM
3)运行时计时(用户 + 内核): ITIMER_PROF -> 27) SIGPROF
NAME
getitimer, setitimer - get or set value of an interval timer
SYNOPSIS
#include <sys/time.h>
int getitimer(int which, struct itimerval *curr_value);
int setitimer(int which, const struct itimerval *new_value,
struct itimerval *old_value);
虚拟时间计时就是用户空间计时,只计算进程占用cpu的时间
运行时间计时就是用户+内核,计算占用cpu以及执行系统调用的时间
使用setitimer函数实现alarm函数,重复计算机1s数数程序