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.
25 .TH TIMER_SETTIME 2 2012-10-15 Linux "Linux Programmer's Manual"
27 timer_settime, timer_gettime \- arm/disarm and fetch
28 state of POSIX per-process timer
33 .BI "int timer_settime(timer_t " timerid ", int " flags ,
34 .BI " const struct itimerspec *" new_value ,
35 .BI " struct itimerspec * " old_value );
36 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
39 Link with \fI\-lrt\fP.
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
48 _POSIX_C_SOURCE\ >=\ 199309L
51 arms or disarms the timer identified by
55 argument is pointer to an
57 structure that specifies the new initial value and
58 the new interval for the timer.
61 structure is defined as follows:
66 time_t tv_sec; /* Seconds */
67 long tv_nsec; /* Nanoseconds */
71 struct timespec it_interval; /* Timer interval */
72 struct timespec it_value; /* Initial expiration */
77 Each of the substructures of the
81 structure that allows a time value to be specified
82 in seconds and nanoseconds.
83 These time values are measured according to the clock
84 that was specified when the timer was created by
88 .I new_value->it_value
89 specifies a nonzero value (i.e., either subfield is nonzero), then
91 arms (starts) the timer,
92 setting it to initially expire at the given time.
93 (If the timer was already armed,
94 then the previous settings are overwritten.)
96 .I new_value->it_value
97 specifies a zero value
98 (i.e., both subfields are zero),
99 then the timer is disarmed.
102 .I new_value->it_interval
103 field specifies the period of the timer, in seconds and nanoseconds.
104 If this field is nonzero, then each time that an armed timer expires,
105 the timer is reloaded from the value specified in
106 .IR new_value->it_interval .
108 .I new_value->it_interval
109 specifies a zero value
110 then the timer expires just once, at the time specified by
113 By default, the initial expiration time specified in
114 .I new_value->it_value
115 is interpreted relative to the current time on the timer's
116 clock at the time of the call.
117 This can be modified by specifying
122 .I new_value->it_value
123 is interpreted as an absolute value as measured on the timer's clock;
124 that is, the timer will expire when the clock value reaches the
126 .IR new_value->it_value .
127 If the specified absolute time has already passed,
128 then the timer expires immediately,
129 and the overrun count (see
130 .BR timer_getoverrun (2))
131 will be set correctly.
132 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
136 clock is adjusted while an absolute timer based on that clock is armed,
137 then the expiration of the timer will be appropriately adjusted.
140 clock have no effect on relative timers based on that clock.
141 .\" Similar remarks might apply with respect to process and thread CPU time
142 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
146 is not NULL, then it points to a buffer
147 that is used to return the previous interval of the timer (in
148 .IR old_value->it_interval )
149 and the amount of time until the timer
150 would previously have next expired (in
151 .IR old_value->it_value ).
154 returns the time until next expiration, and the interval,
155 for the timer specified by
157 in the buffer pointed to by
159 The time remaining until the next timer expiration is returned in
160 .IR curr_value->it_value ;
161 this is always a relative value, regardless of whether the
163 flag was used when arming the timer.
164 If the value returned in
165 .IR curr_value->it_value
166 is zero, then the timer is currently disarmed.
167 The timer interval is returned in
168 .IR curr_value->it_interval .
169 If the value returned in
170 .IR curr_value->it_interval
171 is zero, then this is a "one-shot" timer.
178 On error, \-1 is returned, and
180 is set to indicate the error.
182 These functions may fail with the following errors:
189 is not a valid pointer.
194 .\" FIXME . eventually: invalid value in flags
197 may fail with the following errors:
200 .I new_value.it_value
202 .I new_value.it_value.tv_nsec
203 is negative or greater than 999,999,999.
205 These system calls are available since Linux 2.6.
210 .BR timer_create (2).
212 .BR timer_create (2),
213 .BR timer_getoverrun (2),