Debian Codegraph @

upstream/debian-unstable/man2/timer_settime.2

raw
1 .\" Copyright, the authors of the Linux man-pages project
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH timer_settime 2 2025-10-29 "Linux man-pages 6.18"
6 .SH NAME
7 timer_settime, timer_gettime \- arm/disarm and fetch
8 state of POSIX per-process timer
9 .SH LIBRARY
10 Real-time library
11 .RI ( librt ,\~ \-lrt )
12 .SH SYNOPSIS
13 .nf
14 .B #include <time.h>
15 .P
16 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
17 .BI "int timer_settime(timer_t " timerid ", int " flags ,
18 .BI " const struct itimerspec *restrict " new_value ,
19 .BI " struct itimerspec *_Nullable restrict " old_value );
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR timer_settime (),
28 .BR timer_gettime ():
29 .nf
30 _POSIX_C_SOURCE >= 199309L
31 .fi
32 .SH DESCRIPTION
33 .BR timer_settime ()
34 arms or disarms the timer identified by
35 .IR timerid .
36 The
37 .I new_value
38 argument is pointer to an
39 .I itimerspec
40 structure that specifies the new initial value and
41 the new interval for the timer.
42 The
43 .I itimerspec
44 structure is described in
45 .BR itimerspec (3type).
46 .P
47 Each of the substructures of the
48 .I itimerspec
49 structure is a
50 .BR timespec (3)
51 structure that allows a time value to be specified
52 in seconds and nanoseconds.
53 These time values are measured according to the clock
54 that was specified when the timer was created by
55 .BR timer_create (2).
56 .P
57 If
58 .I new_value\->it_value
59 specifies a nonzero value (i.e., either subfield is nonzero), then
60 .BR timer_settime ()
61 arms (starts) the timer,
62 setting it to initially expire at the given time.
63 (If the timer was already armed,
64 then the previous settings are overwritten.)
65 If
66 .I new_value\->it_value
67 specifies a zero value
68 (i.e., both subfields are zero),
69 then the timer is disarmed.
70 .P
71 The
72 .I new_value\->it_interval
73 field specifies the period of the timer, in seconds and nanoseconds.
74 If this field is nonzero, then each time that an armed timer expires,
75 the timer is reloaded from the value specified in
76 .IR new_value\->it_interval .
77 If
78 .I new_value\->it_interval
79 specifies a zero value,
80 then the timer expires just once, at the time specified by
81 .IR it_value .
82 .P
83 By default, the initial expiration time specified in
84 .I new_value\->it_value
85 is interpreted relative to the current time on the timer's
86 clock at the time of the call.
87 This can be modified by specifying
88 .B TIMER_ABSTIME
89 in
90 .IR flags ,
91 in which case
92 .I new_value\->it_value
93 is interpreted as an absolute value as measured on the timer's clock;
94 that is, the timer will expire when the clock value reaches the
95 value specified by
96 .IR new_value\->it_value .
97 If the specified absolute time has already passed,
98 then the timer expires immediately,
99 and the overrun count (see
100 .BR timer_getoverrun (2))
101 will be set correctly.
102 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
103 .P
104 If the value of the
105 .B CLOCK_REALTIME
106 clock is adjusted while an absolute timer based on that clock is armed,
107 then the expiration of the timer will be appropriately adjusted.
108 Adjustments to the
109 .B CLOCK_REALTIME
110 clock have no effect on relative timers based on that clock.
111 .\" Similar remarks might apply with respect to process and thread CPU time
112 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
113 .P
114 If
115 .I old_value
116 is not NULL, then it points to a buffer
117 that is used to return the previous interval of the timer (in
118 .IR old_value\->it_interval )
119 and the amount of time until the timer
120 would previously have next expired (in
121 .IR old_value\->it_value ).
122 .P
123 .BR timer_gettime ()
124 returns the time until next expiration, and the interval,
125 for the timer specified by
126 .IR timerid ,
127 in the buffer pointed to by
128 .IR curr_value .
129 The time remaining until the next timer expiration is returned in
130 .IR curr_value\->it_value ;
131 this is always a relative value, regardless of whether the
132 .B TIMER_ABSTIME
133 flag was used when arming the timer.
134 If the value returned in
135 .I curr_value\->it_value
136 is zero, then the timer is currently disarmed.
137 The timer interval is returned in
138 .IR curr_value\->it_interval .
139 If the value returned in
140 .I curr_value\->it_interval
141 is zero, then this is a "one-shot" timer.
142 .SH RETURN VALUE
143 On success,
144 .BR timer_settime ()
145 and
146 .BR timer_gettime ()
147 return 0.
148 On error, \-1 is returned, and
149 .I errno
150 is set to indicate the error.
151 .SH ERRORS
152 These functions may fail with the following errors:
153 .TP
154 .B EFAULT
155 .IR new_value ,
156 .IR old_value ,
157 or
158 .I curr_value
159 is not a valid pointer.
160 .TP
161 .B EINVAL
162 .I timerid
163 is invalid.
164 .\" FIXME . eventually: invalid value in flags
165 .P
166 .BR timer_settime ()
167 may fail with the following errors:
168 .TP
169 .B EINVAL
170 .I new_value.it_value
171 is negative;
172 or
173 .I new_value.it_value.tv_nsec
174 is negative or greater than 999,999,999.
175 .SH STANDARDS
176 POSIX.1-2024.
177 .SH HISTORY
178 Linux 2.6.
179 POSIX.1-2001.
180 .SH EXAMPLES
181 See
182 .BR timer_create (2).
183 .SH SEE ALSO
184 .BR timer_create (2),
185 .BR timer_getoverrun (2),
186 .BR timespec (3),
187 .BR time (7)