]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/timer_settime.2
timer_getoverrun.2, timer_settime.2: Add EXAMPLES section referring to example in...
[thirdparty/man-pages.git] / man2 / timer_settime.2
1 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
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"
24 .SH NAME
25 timer_settime, timer_gettime \- arm/disarm and fetch
26 state of POSIX per-process timer
27 .SH SYNOPSIS
28 .nf
29 .B #include <time.h>
30
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 );
35 .fi
36
37 Link with
38 .IR \-lrt .
39 .sp
40 .in -4n
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
43 .in
44 .sp
45 .BR timer_settime (),
46 .BR timer_gettime ():
47 _POSIX_C_SOURCE >= 199309
48 .SH DESCRIPTION
49 .BR timer_settime ()
50 arms or disarms the timer identified by
51 .IR timerid .
52 The
53 .I new_value
54 argument is an
55 .I itimerspec
56 structure that specifies the new initial value and
57 the new interval for the timer.
58 The
59 .I itimerspec
60 structure is defined as follows:
61
62 .in +4n
63 .nf
64 struct timespec {
65 time_t tv_sec; /* Seconds */
66 long tv_nsec; /* Nanoseconds */
67 };
68
69 struct itimerspec {
70 struct timespec it_interval; /* Timer interval */
71 struct timespec it_value; /* Initial expiration */
72 };
73 .fi
74 .in
75
76 Each of the substructures of the
77 .I itimerspec
78 structure is a
79 .I timespec
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
84 .BR timer_create ()
85
86 If
87 .I new_value->it_value
88 specifies a non-zero value (i.e., either subfield is non-zero), then
89 .BR timer_settime ()
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.)
94 If
95 .I new_value->it_value
96 specifies a zero value
97 (i.e., both subfields are zero),
98 then the timer is disarmed.
99
100 The
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 .
106 If
107 .I new_value->it_interval
108 specifies a zero value
109 then the timer expires just once, at the time specified by
110 .IR it_value .
111
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
117 .B TIMER_ABSTIME
118 in
119 .IR flags ,
120 in which case
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
124 value specified by
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.
132
133 If the value of the
134 .B 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.
137 Adjustments to the
138 .B CLOCK_REALTIME
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.
142
143 If
144 .I old_value
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 ).
150
151 .BR timer_gettime ()
152 returns the time until next expiration, and the the interval,
153 for the timer specified by
154 .IR timerid ,
155 in the buffer pointed to by
156 .IR curr_value .
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
160 .BR TIMER_ABSTIME
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.
170 .SH RETURN VALUE
171 On success,
172 .BR timer_settime ()
173 and
174 .BR timer_gettime ()
175 return 0.
176 On error, \-1 is returned, and
177 .I errno
178 is set to indicate the error.
179 .SH ERRORS
180 These functions may fail with the following errors:
181 .TP
182 .B EFAULT
183 .IR new_value ,
184 .IR old_value ,
185 or
186 .I curr_value
187 is not valid a pointer.
188 .TP
189 .B EINVAL
190 .I timerid
191 is invalid.
192 .\" FIXME . eventually: invalid value in flags
193 .PP
194 .BR timer_settime ()
195 may fail with the following errors:
196 .TP
197 .B EINVAL
198 .I new_value.it_value
199 is negative; or
200 .I new_value.it_value.tv_nsec
201 is negative or greater than 999,999,999.
202 .SH VERSIONS
203 These system calls are available since Linux 2.6.
204 .SH CONFORMING TO
205 POSIX.1-2001
206 .SH EXAMPLE
207 See
208 .BR timer_create (2).
209 .SH SEE ALSO
210 .BR timer_create (2),
211 .BR timer_settime (2),
212 .BR timer_getoverrun (2),
213 .BR time (7)