1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH TIMER_SETTIME 2 2021-03-22 Linux "Linux Programmer's Manual"
28 timer_settime, timer_gettime \- arm/disarm and fetch
29 state of POSIX per-process timer
34 .BI "int timer_settime(timer_t " timerid ", int " flags ,
35 .BI " const struct itimerspec *restrict " new_value ,
36 .BI " struct itimerspec *restrict " old_value );
37 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
40 Link with \fI\-lrt\fP.
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
50 _POSIX_C_SOURCE >= 199309L
54 arms or disarms the timer identified by
58 argument is pointer to an
60 structure that specifies the new initial value and
61 the new interval for the timer.
64 structure is defined as follows:
69 time_t tv_sec; /* Seconds */
70 long tv_nsec; /* Nanoseconds */
74 struct timespec it_interval; /* Timer interval */
75 struct timespec it_value; /* Initial expiration */
80 Each of the substructures of the
84 structure that allows a time value to be specified
85 in seconds and nanoseconds.
86 These time values are measured according to the clock
87 that was specified when the timer was created by
91 .I new_value\->it_value
92 specifies a nonzero value (i.e., either subfield is nonzero), then
94 arms (starts) the timer,
95 setting it to initially expire at the given time.
96 (If the timer was already armed,
97 then the previous settings are overwritten.)
99 .I new_value\->it_value
100 specifies a zero value
101 (i.e., both subfields are zero),
102 then the timer is disarmed.
105 .I new_value\->it_interval
106 field specifies the period of the timer, in seconds and nanoseconds.
107 If this field is nonzero, then each time that an armed timer expires,
108 the timer is reloaded from the value specified in
109 .IR new_value\->it_interval .
111 .I new_value\->it_interval
112 specifies a zero value,
113 then the timer expires just once, at the time specified by
116 By default, the initial expiration time specified in
117 .I new_value\->it_value
118 is interpreted relative to the current time on the timer's
119 clock at the time of the call.
120 This can be modified by specifying
125 .I new_value\->it_value
126 is interpreted as an absolute value as measured on the timer's clock;
127 that is, the timer will expire when the clock value reaches the
129 .IR new_value\->it_value .
130 If the specified absolute time has already passed,
131 then the timer expires immediately,
132 and the overrun count (see
133 .BR timer_getoverrun (2))
134 will be set correctly.
135 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
139 clock is adjusted while an absolute timer based on that clock is armed,
140 then the expiration of the timer will be appropriately adjusted.
143 clock have no effect on relative timers based on that clock.
144 .\" Similar remarks might apply with respect to process and thread CPU time
145 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
149 is not NULL, then it points to a buffer
150 that is used to return the previous interval of the timer (in
151 .IR old_value\->it_interval )
152 and the amount of time until the timer
153 would previously have next expired (in
154 .IR old_value\->it_value ).
157 returns the time until next expiration, and the interval,
158 for the timer specified by
160 in the buffer pointed to by
162 The time remaining until the next timer expiration is returned in
163 .IR curr_value\->it_value ;
164 this is always a relative value, regardless of whether the
166 flag was used when arming the timer.
167 If the value returned in
168 .IR curr_value\->it_value
169 is zero, then the timer is currently disarmed.
170 The timer interval is returned in
171 .IR curr_value\->it_interval .
172 If the value returned in
173 .IR curr_value\->it_interval
174 is zero, then this is a "one-shot" timer.
181 On error, \-1 is returned, and
183 is set to indicate the error.
185 These functions may fail with the following errors:
192 is not a valid pointer.
197 .\" FIXME . eventually: invalid value in flags
200 may fail with the following errors:
203 .I new_value.it_value
205 .I new_value.it_value.tv_nsec
206 is negative or greater than 999,999,999.
208 These system calls are available since Linux 2.6.
210 POSIX.1-2001, POSIX.1-2008.
213 .BR timer_create (2).
215 .BR timer_create (2),
216 .BR timer_getoverrun (2),