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 2009-02-16 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 );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
47 _POSIX_C_SOURCE >= 199309
50 arms or disarms the timer identified by
56 structure that specifies the new initial value and
57 the new interval for the timer.
60 structure is defined as follows:
65 time_t tv_sec; /* Seconds */
66 long tv_nsec; /* Nanoseconds */
70 struct timespec it_interval; /* Timer interval */
71 struct timespec it_value; /* Initial expiration */
76 Each of the substructures of the
80 structure that allows a time value to be specified
81 in seconds and nanoseconds.
82 These time values are measured according to the clock
83 that was specified when the timer was created by
87 .I new_value->it_value
88 specifies a non-zero value (i.e., either subfield is non-zero), then
90 arms (starts) the timer,
91 setting it to initially expire at the given time.
92 (If the timer was already armed,
93 then the previous settings are overwritten.)
95 .I new_value->it_value
96 specifies a zero value
97 (i.e., both subfields are zero),
98 then the timer is disarmed.
101 .I new_value->it_interval
102 field specifies the period of the timer, in seconds and nanoseconds.
103 If this field is non-zero, then each time that an armed timer expires,
104 the timer is reloaded from the value specified in
105 .IR new_value->it_interval .
107 .I new_value->it_interval
108 specifies a zero value
109 then the timer expires just once, at the time specified by
112 By default, the initial expiration time specified in
113 .I new_value->it_value
114 is interpreted relative to the current time on the timer's
115 clock at the time of the call.
116 This can be modified by specifying
121 .I new_value->it_value
122 is interpreted as an absolute value as measured on the timer's clock;
123 that is, the timer will expire when the clock value reaches the
125 .IR new_value->it_value .
126 If the specified absolute time has already passed,
127 then the timer expires immediately,
128 and the overrun count (see
129 .BR timer_getoverrun (2))
130 will be set correctly.
131 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
135 clock is adjusted while an absolute timer based on that clock is armed,
136 then the expiration of the timer will be appropriately adjusted.
139 clock have no effect on relative timers based on that clock.
140 .\" Similar remarks might apply with respect to process and thread CPU time
141 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
145 is not NULL, then it returns 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 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 valid a 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.
207 .BR timer_create (2),
208 .BR timer_settime (2),
209 .BR timer_getoverrun (2),