The system offers each process three interval timers that are declared in the sys/time.h file. The getitimer() call stores the current value of the which timer in the structure to which value points. The setitimer() call sets the value of which to the value in the structure to which value points; if ovalue is not zero, the previous value of the timer is stored in the structure to which ovalue points. The setting of a timer is defined via the itimerval structure (see sys/time.h ), which contains at least the following components: struct timeval it_interval; /* Clock interval */
struct timeval it_value; /* Current value */
If it_value is not zero, the time until the next expiry of the timer is specified. If it_interval is not zero, a value is specified to which it_value is set if the timer expires. If it_value is set to zero, the timer is deactivated, regardless of the value of it_interval . Setting it_interval to zero deactivates the timer after its next expiry (provided it_value is not zero). If time values are smaller than the resolution of the system clock, they are rounded to the system clock’s resolution. Each process has three timers at its disposal which can be addressed via the following values for which: ITIMER_REAL
| decrements in real time. The SIGALRM signal is sent when this timer expires. | ITIMER_VIRTUAL
| decrements in the virtual process time. This timer only runs when the process is executed. The SIGVTALRM signal is sent when this timer expires. | ITIMER_PROF
| decrements in virtual process time, regardless of ITIMER_VIRTUAL . Whenever the ITIMER_PROF timer expires, the SIGPROF signal is sent. Because this signal interrupts system calls of the process, the programs which use this timer must be prepared to repeat the interrupted system calls. |
setitimer() and sleep() or usleep() should not be used together, as this may result in undesirable interactions - in particular, a sleep() call signs on its own signal handling routine, so the signal handling routine of the user is not activated.
|