1TIMER_SETTIME(2) Linux Programmer's Manual TIMER_SETTIME(2)
2
3
4
6 timer_settime, timer_gettime - arm/disarm and fetch state of POSIX per-
7 process timer
8
10 #include <time.h>
11
12 int timer_settime(timer_t timerid, int flags,
13 const struct itimerspec *restrict new_value,
14 struct itimerspec *restrict old_value);
15 int timer_gettime(timer_t timerid, struct itimerspec *curr_value);
16
17 Link with -lrt.
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 timer_settime(), timer_gettime():
22 _POSIX_C_SOURCE >= 199309L
23
25 timer_settime() arms or disarms the timer identified by timerid. The
26 new_value argument is pointer to an itimerspec structure that specifies
27 the new initial value and the new interval for the timer. The itimer‐
28 spec structure is defined as follows:
29
30 struct timespec {
31 time_t tv_sec; /* Seconds */
32 long tv_nsec; /* Nanoseconds */
33 };
34
35 struct itimerspec {
36 struct timespec it_interval; /* Timer interval */
37 struct timespec it_value; /* Initial expiration */
38 };
39
40 Each of the substructures of the itimerspec structure is a timespec
41 structure that allows a time value to be specified in seconds and
42 nanoseconds. These time values are measured according to the clock
43 that was specified when the timer was created by timer_create(2).
44
45 If new_value->it_value specifies a nonzero value (i.e., either subfield
46 is nonzero), then timer_settime() arms (starts) the timer, setting it
47 to initially expire at the given time. (If the timer was already
48 armed, then the previous settings are overwritten.) If
49 new_value->it_value specifies a zero value (i.e., both subfields are
50 zero), then the timer is disarmed.
51
52 The new_value->it_interval field specifies the period of the timer, in
53 seconds and nanoseconds. If this field is nonzero, then each time that
54 an armed timer expires, the timer is reloaded from the value specified
55 in new_value->it_interval. If new_value->it_interval specifies a zero
56 value, then the timer expires just once, at the time specified by
57 it_value.
58
59 By default, the initial expiration time specified in
60 new_value->it_value is interpreted relative to the current time on the
61 timer's clock at the time of the call. This can be modified by speci‐
62 fying TIMER_ABSTIME in flags, in which case new_value->it_value is in‐
63 terpreted as an absolute value as measured on the timer's clock; that
64 is, the timer will expire when the clock value reaches the value speci‐
65 fied by new_value->it_value. If the specified absolute time has al‐
66 ready passed, then the timer expires immediately, and the overrun count
67 (see timer_getoverrun(2)) will be set correctly.
68
69 If the value of the CLOCK_REALTIME clock is adjusted while an absolute
70 timer based on that clock is armed, then the expiration of the timer
71 will be appropriately adjusted. Adjustments to the CLOCK_REALTIME
72 clock have no