getitimer(), setitimer() - get and set value of interval timer
#include <sys/time.h>
int getitimer (int which, struct itimerval *value);
int setitimer (int which, struct itimerval *value,
struct itimerval *ovalue);
The getitimer(2) call stores the current value of the which timer into the structure pointed to by value. The setitimer(2) call sets the timer indicated by which to the value stored in the structure value. The previous value of the timer is stored in ovalue, if ovalue is not NULL.
The which argument specifies one of three types of timers (defined in <sys/time.h>):
The itimerval structure defines a timer value:
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
The timeval structure is:
struct timeval {
time_t tv_sec;
long tv_usec;
};
If the value of it_value is non-zero, it is a time until the next timer expiration. If the value is zero, then getitimer(2) disables a timer when it is called, regardless of the value of it_interval.
If the value of it_interval is non-zero, it is an interval value which will be placed in it_value after the timer expires. If the value is zero, then the timer is disabled after the next time it expires.
The value must be in canonical form: the number of microseconds (tv_usec) must be less than 1,000,000 (a million) and neither the number of seconds (tv_sec) or microseconds (tv_usec) can be negative integers.
Three traditional macros are also defined in <sys/time.h> for setting and testing timer values.
The getitimer(2) utility exits with status 0 for success, and >0 if an error occurred.
The getitimer(2) and setitimer(2) calls can fail for the following reasons:
The setitimer(2) call can also fail because:
alarm(2)
sleep(3)