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 2015-08-08 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 *" new_value ,
36 .BI " struct itimerspec *" 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)):
49 _POSIX_C_SOURCE\ >=\ 199309L
52 arms or disarms the timer identified by
56 argument is pointer to an
58 structure that specifies the new initial value and
59 the new interval for the timer.
62 structure is defined as follows:
67 time_t tv_sec; /* Seconds */
68 long tv_nsec; /* Nanoseconds */
72 struct timespec it_interval; /* Timer interval */
73 struct timespec it_value; /* Initial expiration */
78 Each of the substructures of the
82 structure that allows a time value to be specified
83 in seconds and nanoseconds.
84 These time values are measured according to the clock
85 that was specified when the timer was created by
89 .I new_value->it_value
90 specifies a nonzero value (i.e., either subfield is nonzero), then
92 arms (starts) the timer,
93 setting it to initially expire at the given time.
94 (If the timer was already armed,
95 then the previous settings are overwritten.)
97 .I new_value->it_value
98 specifies a zero value
99 (i.e., both subfields are zero),
100 then the timer is disarmed.
103 .I new_value->it_interval
104 field specifies the period of the timer, in seconds and nanoseconds.
105 If this field is nonzero, then each time that an armed timer expires,
106 the timer is reloaded from the value specified in
107 .IR new_value->it_interval .
109 .I new_value->it_interval
110 specifies a zero value,
111 then the timer expires just once, at the time specified by
114 By default, the initial expiration time specified in
115 .I new_value->it_value
116 is interpreted relative to the current time on the timer's
117 clock at the time of the call.
118 This can be modified by specifying
123 .I new_value->it_value
124 is interpreted as an absolute value as measured on the timer's clock;
125 that is, the timer will expire when the clock value reaches the
127 .IR new_value->it_value .
128 If the specified absolute time has already passed,
129 then the timer expires immediately,
130 and the overrun count (see
131 .BR timer_getoverrun (2))
132 will be set correctly.
133 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
137 clock is adjusted while an absolute timer based on that clock is armed,
138 then the expiration of the timer will be appropriately adjusted.
141 clock have no effect on relative timers based on that clock.
142 .\" Similar remarks might apply with respect to process and thread CPU time
143 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
147 is not NULL, then it points to a buffer
148 that is used to return the previous interval of the timer (in
149 .IR old_value->it_interval )
150 and the amount of time until the timer
151 would previously have next expired (in
152 .IR old_value->it_value ).
155 returns the time until next expiration, and the interval,
156 for the timer specified by
158 in the buffer pointed to by
160 The time remaining until the next timer expiration is returned in
161 .IR curr_value->it_value ;
162 this is always a relative value, regardless of whether the
164 flag was used when arming the timer.
165 If the value returned in
166 .IR curr_value->it_value
167 is zero, then the timer is currently disarmed.
168 The timer interval is returned in
169 .IR curr_value->it_interval .
170 If the value returned in
171 .IR curr_value->it_interval
172 is zero, then this is a "one-shot" timer.
179 On error, \-1 is returned, and
181 is set to indicate the error.
183 These functions may fail with the following errors:
190 is not a valid pointer.
195 .\" FIXME . eventually: invalid value in flags
198 may fail with the following errors:
201 .I new_value.it_value
203 .I new_value.it_value.tv_nsec
204 is negative or greater than 999,999,999.
206 These system calls are available since Linux 2.6.
208 POSIX.1-2001, POSIX.1-2008.
211 .BR timer_create (2).
213 .BR timer_create (2),
214 .BR timer_getoverrun (2),