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 effect on relative timers based on that clock.
73
74 If old_value is not NULL, then it points to a buffer that is used to
75 return the previous interval of the timer (in old_value->it_interval)
76 and the amount of time until the timer would previously have next ex‐
77 pired (in old_value->it_value).
78
79 timer_gettime() returns the time until next expiration, and the inter‐
80 val, for the timer specified by timerid, in the buffer pointed to by
81 curr_value. The time remaining until the next timer expiration is re‐
82 turned in curr_value->it_value; this is always a relative value, re‐
83 gardless of whether the TIMER_ABSTIME flag was used when arming the
84 timer. If the value returned in curr_value->it_value is zero, then the
85 timer is currently disarmed. The timer interval is returned in
86 curr_value->it_interval. If the value returned in curr_value->it_in‐
87 terval is zero, then this is a "one-shot" timer.
88
90 On success, timer_settime() and timer_gettime() return 0. On error, -1
91 is returned, and errno is set to indicate the error.
92
94 These functions may fail with the following errors:
95
96 EFAULT new_value, old_value, or curr_value is not a valid pointer.
97
98 EINVAL timerid is invalid.
99
100 timer_settime() may fail with the following errors:
101
102 EINVAL new_value.it_value is negative; or new_value.it_value.tv_nsec is
103 negative or greater than 999,999,999.
104
106 These system calls are available since Linux 2.6.
107
109 POSIX.1-2001, POSIX.1-2008.
110
112 See timer_create(2).
113
115 timer_create(2), timer_getoverrun(2), time(7)
116
118 This page is part of release 5.13 of the Linux man-pages project. A
119 description of the project, information about reporting bugs, and the
120 latest version of this page, can be found at
121 https://www.kernel.org/doc/man-pages/.
122
123
124
125Linux 2021-03-22 TIMER_SETTIME(2)