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 *new_value,
14 struct itimerspec *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(): _POSIX_C_SOURCE >= 199309L
22
24 timer_settime() arms or disarms the timer identified by timerid. The
25 new_value argument is pointer to an itimerspec structure that specifies
26 the new initial value and the new interval for the timer. The itimer‐
27 spec structure is defined as follows:
28
29 struct timespec {
30 time_t tv_sec; /* Seconds */
31 long tv_nsec; /* Nanoseconds */
32 };
33
34 struct itimerspec {
35 struct timespec it_interval; /* Timer interval */
36 struct timespec it_value; /* Initial expiration */
37 };
38
39 Each of the substructures of the itimerspec structure is a timespec
40 structure that allows a time value to be specified in seconds and
41 nanoseconds. These time values are measured according to the clock
42 that was specified when the timer was created by timer_create(2).
43
44 If new_value->it_value specifies a nonzero value (i.e., either subfield
45 is nonzero), then timer_settime() arms (starts) the timer, setting it
46 to initially expire at the given time. (If the timer was already
47 armed, then the previous settings are overwritten.) If
48 new_value->it_value specifies a zero value (i.e., both subfields are
49 zero), then the timer is disarmed.
50
51 The new_value->it_interval field specifies the period of the timer, in
52 seconds and nanoseconds. If this field is nonzero, then each time that
53 an armed timer expires, the timer is reloaded from the value specified
54 in new_value->it_interval. If new_value->it_interval specifies a zero
55 value, then the timer expires just once, at the time specified by
56 it_value.
57
58 By default, the initial expiration time specified in
59 new_value->it_value is interpreted relative to the current time on the
60 timer's clock at the time of the call. This can be modified by speci‐
61 fying TIMER_ABSTIME in flags, in which case new_value->it_value is
62 interpreted as an absolute value as measured on the timer's clock; that
63 is, the timer will expire when the clock value reaches the value speci‐
64 fied by new_value->it_value. If the specified absolute time has
65 already passed, then the timer expires immediately, and the overrun
66 count (see timer_getoverrun(2)) will be set correctly.
67
68 If the value of the CLOCK_REALTIME clock is adjusted while an absolute
69 timer based on that clock is armed, then the expiration of the timer
70 will be appropriately adjusted. Adjustments to the CLOCK_REALTIME
71 clock have no effect on relative timers based on that clock.
72
73 If old_value is not NULL, then it points to a buffer that is used to
74 return the previous interval of the timer (in old_value->it_interval)
75 and the amount of time until the timer would previously have next
76 expired (in old_value->it_value).
77
78 timer_gettime() returns the time until next expiration, and the inter‐
79 val, for the timer specified by timerid, in the buffer pointed to by
80 curr_value. The time remaining until the next timer expiration is
81 returned in curr_value->it_value; this is always a relative value,
82 regardless of whether the TIMER_ABSTIME flag was used when arming the
83 timer. If the value returned in curr_value->it_value is zero, then the
84 timer is currently disarmed. The timer interval is returned in
85 curr_value->it_interval. If the value returned in
86 curr_value->it_interval is zero, then this is a "one-shot" timer.
87
89 On success, timer_settime() and timer_gettime() return 0. On error, -1
90 is returned, and errno is set to indicate the error.
91
93 These functions may fail with the following errors:
94
95 EFAULT new_value, old_value, or curr_value is not a valid pointer.
96
97 EINVAL timerid is invalid.
98
99 timer_settime() may fail with the following errors:
100
101 EINVAL new_value.it_value is negative; or new_value.it_value.tv_nsec is
102 negative or greater than 999,999,999.
103
105 These system calls are available since Linux 2.6.
106
108 POSIX.1-2001, POSIX.1-2008.
109
111 See timer_create(2).
112
114 timer_create(2), timer_getoverrun(2), time(7)
115
117 This page is part of release 5.07 of the Linux man-pages project. A
118 description of the project, information about reporting bugs, and the
119 latest version of this page, can be found at
120 https://www.kernel.org/doc/man-pages/.
121
122
123
124Linux 2020-06-09 TIMER_SETTIME(2)