setitimer()

Updated: April 19, 2023

Set the value of an interval timer

Synopsis:

#include <sys/time.h>

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

Arguments:

which
The interval timer whose value you want to set. Currently, this must be ITIMER_REAL.
value
A pointer to an itimerval structure that specifies the value that you want to set the interval timer to.
ovalue
NULL, or a pointer to an itimerval structure where the function can store the old value of the interval timer.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The setitimer() function sets the value of the timer specified by which to the value specified in the structure pointed to by value, and if ovalue isn't NULL, stores the previous value of the timer in the structure it points to.

The setitimer() function is independent of alarm().

Note: You should use timer_gettime() and timer_settime() instead of the obsolescent getitimer() and setitimer().

A timer value is defined by the itimerval structure, which includes the following members:

struct timeval    it_interval;    /* timer interval */
struct timeval    it_value;       /* current value */

Each struct timeval contains the following members:

The it_value member indicates the time to the next timer expiration. The it_interval member specifies a value to be used in reloading it_value when the timer expires. Setting it_value to 0 disables a timer, regardless of the value of it_interval. Setting it_interval to 0 disables a timer after its next expiration (assuming it_value is nonzero).

Time values smaller than the resolution of the system clock are rounded up to the resolution of the system clock.

The only supported timer is ITIMER_REAL, which decrements in real time. A SIGALRM signal is delivered when this timer expires.

Note: Because of the nature of time measurement, the timer might actually expire later than the specified time. For more information, see the Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide.

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

EINVAL
The specified number of seconds is greater than 100,000,000, the number of microseconds is greater than or equal to 1,000,000, or the which argument is unrecognized.

Classification:

POSIX 1003.1 OB XSI. This function is marked as obsolescent, and may be removed from a future version of the standard.

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes