1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH TIMER_SETTIME 2 2012-10-15 Linux "Linux Programmer's Manual"
25 timer_settime, timer_gettime \- arm/disarm and fetch
26 state of POSIX per-process timer
31 .BI "int timer_settime(timer_t " timerid ", int " flags ,
32 .BI " const struct itimerspec *" new_value ,
33 .BI " struct itimerspec * " old_value );
34 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
37 Link with \fI\-lrt\fP.
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
46 _POSIX_C_SOURCE\ >=\ 199309L
49 arms or disarms the timer identified by
53 argument is pointer to an
55 structure that specifies the new initial value and
56 the new interval for the timer.
59 structure is defined as follows:
64 time_t tv_sec; /* Seconds */
65 long tv_nsec; /* Nanoseconds */
69 struct timespec it_interval; /* Timer interval */
70 struct timespec it_value; /* Initial expiration */
75 Each of the substructures of the
79 structure that allows a time value to be specified
80 in seconds and nanoseconds.
81 These time values are measured according to the clock
82 that was specified when the timer was created by
86 .I new_value->it_value
87 specifies a nonzero value (i.e., either subfield is nonzero), then
89 arms (starts) the timer,
90 setting it to initially expire at the given time.
91 (If the timer was already armed,
92 then the previous settings are overwritten.)
94 .I new_value->it_value
95 specifies a zero value
96 (i.e., both subfields are zero),
97 then the timer is disarmed.
100 .I new_value->it_interval
101 field specifies the period of the timer, in seconds and nanoseconds.
102 If this field is nonzero, then each time that an armed timer expires,
103 the timer is reloaded from the value specified in
104 .IR new_value->it_interval .
106 .I new_value->it_interval
107 specifies a zero value
108 then the timer expires just once, at the time specified by
111 By default, the initial expiration time specified in
112 .I new_value->it_value
113 is interpreted relative to the current time on the timer's
114 clock at the time of the call.
115 This can be modified by specifying
120 .I new_value->it_value
121 is interpreted as an absolute value as measured on the timer's clock;
122 that is, the timer will expire when the clock value reaches the
124 .IR new_value->it_value .
125 If the specified absolute time has already passed,
126 then the timer expires immediately,
127 and the overrun count (see
128 .BR timer_getoverrun (2))
129 will be set correctly.
130 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
134 clock is adjusted while an absolute timer based on that clock is armed,
135 then the expiration of the timer will be appropriately adjusted.
138 clock have no effect on relative timers based on that clock.
139 .\" Similar remarks might apply with respect to process and thread CPU time
140 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
144 is not NULL, then it points to a buffer
145 that is used to return the previous interval of the timer (in
146 .IR old_value->it_interval )
147 and the amount of time until the timer
148 would previously have next expired (in
149 .IR old_value->it_value ).
152 returns the time until next expiration, and the interval,
153 for the timer specified by
155 in the buffer pointed to by
157 The time remaining until the next timer expiration is returned in
158 .IR curr_value->it_value ;
159 this is always a relative value, regardless of whether the
161 flag was used when arming the timer.
162 If the value returned in
163 .IR curr_value->it_value
164 is zero, then the timer is currently disarmed.
165 The timer interval is returned in
166 .IR curr_value->it_interval .
167 If the value returned in
168 .IR curr_value->it_interval
169 is zero, then this is a "one-shot" timer.
176 On error, \-1 is returned, and
178 is set to indicate the error.
180 These functions may fail with the following errors:
187 is not a valid pointer.
192 .\" FIXME . eventually: invalid value in flags
195 may fail with the following errors:
198 .I new_value.it_value
200 .I new_value.it_value.tv_nsec
201 is negative or greater than 999,999,999.
203 These system calls are available since Linux 2.6.
208 .BR timer_create (2).
210 .BR timer_create (2),
211 .BR timer_getoverrun (2),