mount_setattr.2: SEE ALSO: place entries in correct order
[man-pages.git] / man2 / timer_settime.2
blob10687b21111d877a3440a70e285a74b54c325c2b
1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH TIMER_SETTIME 2 2021-03-22 Linux "Linux Programmer's Manual"
27 .SH NAME
28 timer_settime, timer_gettime \- arm/disarm and fetch
29 state of POSIX per-process timer
30 .SH SYNOPSIS
31 .nf
32 .B  #include <time.h>
33 .PP
34 .BI "int timer_settime(timer_t " timerid ", int " flags ,
35 .BI "                  const struct itimerspec *restrict " new_value ,
36 .BI "                  struct itimerspec *restrict " old_value );
37 .BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
38 .fi
39 .PP
40 Link with \fI\-lrt\fP.
41 .PP
42 .RS -4
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
45 .RE
46 .PP
47 .BR timer_settime (),
48 .BR timer_gettime ():
49 .nf
50     _POSIX_C_SOURCE >= 199309L
51 .fi
52 .SH DESCRIPTION
53 .BR timer_settime ()
54 arms or disarms the timer identified by
55 .IR timerid .
56 The
57 .I new_value
58 argument is pointer to an
59 .I itimerspec
60 structure that specifies the new initial value and
61 the new interval for the timer.
62 The
63 .I itimerspec
64 structure is defined as follows:
65 .PP
66 .in +4n
67 .EX
68 struct timespec {
69     time_t tv_sec;                /* Seconds */
70     long   tv_nsec;               /* Nanoseconds */
73 struct itimerspec {
74     struct timespec it_interval;  /* Timer interval */
75     struct timespec it_value;     /* Initial expiration */
77 .EE
78 .in
79 .PP
80 Each of the substructures of the
81 .I itimerspec
82 structure is a
83 .I timespec
84 structure that allows a time value to be specified
85 in seconds and nanoseconds.
86 These time values are measured according to the clock
87 that was specified when the timer was created by
88 .BR timer_create (2).
89 .PP
91 .I new_value\->it_value
92 specifies a nonzero value (i.e., either subfield is nonzero), then
93 .BR timer_settime ()
94 arms (starts) the timer,
95 setting it to initially expire at the given time.
96 (If the timer was already armed,
97 then the previous settings are overwritten.)
99 .I new_value\->it_value
100 specifies a zero value
101 (i.e., both subfields are zero),
102 then the timer is disarmed.
105 .I new_value\->it_interval
106 field specifies the period of the timer, in seconds and nanoseconds.
107 If this field is nonzero, then each time that an armed timer expires,
108 the timer is reloaded from the value specified in
109 .IR new_value\->it_interval .
111 .I new_value\->it_interval
112 specifies a zero value,
113 then the timer expires just once, at the time specified by
114 .IR it_value .
116 By default, the initial expiration time specified in
117 .I new_value\->it_value
118 is interpreted relative to the current time on the timer's
119 clock at the time of the call.
120 This can be modified by specifying
121 .B TIMER_ABSTIME
123 .IR flags ,
124 in which case
125 .I new_value\->it_value
126 is interpreted as an absolute value as measured on the timer's clock;
127 that is, the timer will expire when the clock value reaches the
128 value specified by
129 .IR new_value\->it_value .
130 If the specified absolute time has already passed,
131 then the timer expires immediately,
132 and the overrun count (see
133 .BR timer_getoverrun (2))
134 will be set correctly.
135 .\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
137 If the value of the
138 .B CLOCK_REALTIME
139 clock is adjusted while an absolute timer based on that clock is armed,
140 then the expiration of the timer will be appropriately adjusted.
141 Adjustments to the
142 .B CLOCK_REALTIME
143 clock have no effect on relative timers based on that clock.
144 .\" Similar remarks might apply with respect to process and thread CPU time
145 .\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
148 .I old_value
149 is not NULL, then it points to a buffer
150 that is used to return the previous interval of the timer (in
151 .IR old_value\->it_interval )
152 and the amount of time until the timer
153 would previously have next expired (in
154 .IR old_value\->it_value ).
156 .BR timer_gettime ()
157 returns the time until next expiration, and the interval,
158 for the timer specified by
159 .IR timerid ,
160 in the buffer pointed to by
161 .IR curr_value .
162 The time remaining until the next timer expiration is returned in
163 .IR curr_value\->it_value ;
164 this is always a relative value, regardless of whether the
165 .BR TIMER_ABSTIME
166 flag was used when arming the timer.
167 If the value returned in
168 .IR curr_value\->it_value
169 is zero, then the timer is currently disarmed.
170 The timer interval is returned in
171 .IR curr_value\->it_interval .
172 If the value returned in
173 .IR curr_value\->it_interval
174 is zero, then this is a "one-shot" timer.
175 .SH RETURN VALUE
176 On success,
177 .BR timer_settime ()
179 .BR timer_gettime ()
180 return 0.
181 On error, \-1 is returned, and
182 .I errno
183 is set to indicate the error.
184 .SH ERRORS
185 These functions may fail with the following errors:
187 .B EFAULT
188 .IR new_value ,
189 .IR old_value ,
191 .I curr_value
192 is not a valid pointer.
194 .B EINVAL
195 .I timerid
196 is invalid.
197 .\" FIXME . eventually: invalid value in flags
199 .BR timer_settime ()
200 may fail with the following errors:
202 .B EINVAL
203 .I new_value.it_value
204 is negative; or
205 .I new_value.it_value.tv_nsec
206 is negative or greater than 999,999,999.
207 .SH VERSIONS
208 These system calls are available since Linux 2.6.
209 .SH CONFORMING TO
210 POSIX.1-2001, POSIX.1-2008.
211 .SH EXAMPLES
213 .BR timer_create (2).
214 .SH SEE ALSO
215 .BR timer_create (2),
216 .BR timer_getoverrun (2),
217 .BR time (7)