Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getitimer, setitimer - read or set

&pagelevel(4)&pagelevel

Syntax

#include <sys/time.h>

int getitimer(int which, struct itimerval *value);

int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue); 

Description

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. 

Return val.

0

-1

if successful.

if an error occurs. errno is set to indicate the error.

Errors

setitimer() will fail if:

 

EINVAL

The values to which the value argument points are invalid. (For the microseconds a non-negative integer lower than 1,000,000 must be specified, for the seconds a non-negative integer.)


getitimer() and setitimer() will fail if:

 

EINVAL

The which parameter was not recognized

 Notes

The field with the microseconds must not contain a value greater than or equal to one second.

 See also

alarm(), sleep(), ualarm(), usleep(), signal.h, sys/time.h.