1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH timer_settime 2 (date) "Linux man-pages (unreleased)"
8 timer_settime, timer_gettime \- arm/disarm and fetch
9 state of POSIX per-process timer
12 .RI ( librt ", " \-lrt )
17 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
18 .BI "int timer_settime(timer_t " timerid ", int " flags ,
19 .BI " const struct itimerspec *restrict " new_value ,
20 .BI " struct itimerspec *_Nullable restrict " old_value );
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
31 _POSIX_C_SOURCE >= 199309L
35 arms or disarms the timer identified by
39 argument is pointer to an
41 structure that specifies the new initial value and
42 the new interval for the timer.
45 structure is described in
46 .BR itimerspec (3type).
48 Each of the substructures of the
52 structure that allows a time value to be specified
53 in seconds and nanoseconds.
54 These time values are measured according to the clock
55 that was specified when the timer was created by
59 .I new_value\->it_value
60 specifies a nonzero value (i.e., either subfield is nonzero), then
62 arms (starts) the timer,
63 setting it to initially expire at the given time.
64 (If the timer was already armed,
65 then the previous settings are overwritten.)
67 .I new_value\->it_value
68 specifies a zero value
69 (i.e., both subfields are zero),
70 then the timer is disarmed.
73 .I new_value\->it_interval
74 field specifies the period of the timer, in seconds and nanoseconds.
75 If this field is nonzero, then each time that an armed timer expires,
76 the timer is reloaded from the value specified in
77 .IR new_value\->it_interval .
79 .I new_value\->it_interval
80 specifies a zero value,
81 then the timer expires just once, at the time specified by
84 By default, the initial expiration time specified in
85 .I new_value\->it_value
86 is interpreted relative to the current time on the timer's
87 clock at the time of the call.
88 This can be modified by specifying
93 .I new_value\->it_value
94 is interpreted as an absolute value as measured on the timer's clock;
95 that is, the timer will expire when the clock value reaches the
97 .IR new_value\->it_value .
98 If the specified absolute time has already passed,
99 then the timer expires immediately,
100 and the overrun count (see
101 .BR timer_getoverrun (2))
102 will be set correctly.
103 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
107 clock is adjusted while an absolute timer based on that clock is armed,
108 then the expiration of the timer will be appropriately adjusted.
111 clock have no effect on relative timers based on that clock.
112 .\" Similar remarks might apply with respect to process and thread CPU time
113 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
117 is not NULL, then it points to a buffer
118 that is used to return the previous interval of the timer (in
119 .IR old_value\->it_interval )
120 and the amount of time until the timer
121 would previously have next expired (in
122 .IR old_value\->it_value ).
125 returns the time until next expiration, and the interval,
126 for the timer specified by
128 in the buffer pointed to by
130 The time remaining until the next timer expiration is returned in
131 .IR curr_value\->it_value ;
132 this is always a relative value, regardless of whether the
134 flag was used when arming the timer.
135 If the value returned in
136 .I curr_value\->it_value
137 is zero, then the timer is currently disarmed.
138 The timer interval is returned in
139 .IR curr_value\->it_interval .
140 If the value returned in
141 .I curr_value\->it_interval
142 is zero, then this is a "one-shot" timer.
149 On error, \-1 is returned, and
151 is set to indicate the error.
153 These functions may fail with the following errors:
160 is not a valid pointer.
165 .\" FIXME . eventually: invalid value in flags
168 may fail with the following errors:
171 .I new_value.it_value
173 .I new_value.it_value.tv_nsec
174 is negative or greater than 999,999,999.
182 .BR timer_create (2).
184 .BR timer_create (2),
185 .BR timer_getoverrun (2),