]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/sys/timer_settime.2
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / sys / timer_settime.2
1 .\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice(s), this list of conditions and the following disclaimer as
9 .\"    the first lines of this file unmodified other than the possible
10 .\"    addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice(s), this list of conditions and the following disclaimer in
13 .\"    the documentation and/or other materials provided with the
14 .\"    distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\"
30 .Dd September 11, 2000
31 .Dt TIMER_SETTIME 2
32 .Os
33 .Sh NAME
34 .Nm timer_getoverrun ,
35 .Nm timer_gettime ,
36 .Nm timer_settime
37 .Nd "per-process timers (REALTIME)"
38 .Sh LIBRARY
39 .Lb librt
40 .Sh SYNOPSIS
41 .In time.h
42 .Ft int
43 .Fn timer_getoverrun "timer_t timerid"
44 .Ft int
45 .Fn timer_gettime "timer_t timerid" "struct itimerspec *value"
46 .Ft int
47 .Fo timer_settime
48 .Fa "timer_t timerid" "int flags" "const struct itimerspec *restrict value"
49 .Fa "struct itimerspec *restrict ovalue"
50 .Fc
51 .Sh DESCRIPTION
52 The
53 .Fn timer_gettime
54 system call stores the amount of time until the specified timer,
55 .Fa timerid ,
56 expires and the reload value of the timer into the space pointed to by the
57 .Fa value
58 argument.
59 The
60 .Va it_value
61 member of this structure contains the amount of time
62 before the timer expires, or zero if the timer is disarmed.
63 This value is
64 returned as the interval until timer expiration, even if the timer was armed
65 with absolute time.
66 The
67 .Va it_interval
68 member of
69 .Fa value
70 contains the reload
71 value last set by
72 .Fn timer_settime .
73 .Pp
74 The
75 .Fn timer_settime
76 system call sets the time until the next expiration of the timer specified
77 by
78 .Fa timerid
79 from the
80 .Va it_value
81 member of the
82 .Fa value
83 argument and arms the timer if the
84 .Va it_value
85 member of
86 .Fa value
87 is non-zero.
88 If the specified timer was already
89 armed when
90 .Fn timer_settime
91 is called, this call resets the time until next expiration to the value
92 specified.
93 If the
94 .Va it_value
95 member of
96 .Fa value
97 is zero, the timer is disarmed.
98 If the timer is disarmed, then pending signal is removed.
99 .Pp
100 If the flag
101 .Dv TIMER_ABSTIME
102 is not set in the argument
103 .Fa flags ,
104 .Fn timer_settime
105 behaves as if the time until next expiration is set to
106 be equal to the interval specified by the
107 .Va it_value
108 member of
109 .Fa value .
110 That is,
111 the timer expires in
112 .Va it_value
113 nanoseconds from when the call is made.
114 If the flag
115 .Dv TIMER_ABSTIME
116 is set in the argument
117 .Fa flags ,
118 .Fn timer_settime
119 behaves as if the time until next expiration is set to be equal to the
120 difference between the absolute time specified by the it_value member of
121 value and the current value of the clock associated with
122 .Fa timerid .
123 That is, the timer expires when the clock reaches the value specified by the
124 .Va it_value
125 member of
126 .Fa value .
127 If the specified time has already passed, the
128 system call succeeds and the expiration notification is made.
129 .Pp
130 The reload value of the timer is set to the value specified by the
131 .Va it_interval
132 member of
133 .Fa value .
134 When a timer is armed with a non-zero
135 .Va it_interval ,
136 a periodic
137 (or repetitive) timer is specified.
138 .Pp
139 Time values that are between two consecutive non-negative integer multiples of
140 the resolution of the specified timer are rounded up to the larger multiple of
141 the resolution.
142 Quantization error will not cause the timer to expire earlier
143 than the rounded time value.
144 .Pp
145 If the argument
146 .Fa ovalue
147 is not
148 .Dv NULL ,
149 the
150 .Fn timer_settime
151 system call stores, in the location referenced by
152 .Fa ovalue ,
153 a value representing
154 the previous amount of time before the timer would have expired, or zero if the
155 timer was disarmed, together with the previous timer reload value.
156 Timers do not
157 expire before their scheduled time.
158 .Pp
159 Only a single signal is queued to the process for a given timer at any point in
160 time.
161 When a timer for which a signal is still pending expires, no signal is
162 queued, and a timer overrun will occur.
163 When a timer expiration signal is
164 accepted by a process, the
165 .Fn timer_getoverrun
166 system call returns the timer expiration overrun count for the specified timer.
167 The overrun count returned contains the number of extra timer expirations that
168 occurred between the time the signal was generated (queued) and when it was
169 accepted, up to but not including an maximum of
170 .Brq Dv DELAYTIMER_MAX .
171 If the number of
172 such extra expirations is greater than or equal to
173 .Brq Dv DELAYTIMER_MAX ,
174 then the overrun count is set to
175 .Brq Dv DELAYTIMER_MAX .
176 The value returned by
177 .Fn timer_getoverrun
178 applies to the most recent expiration signal acceptance for the timer.
179 If no
180 expiration signal has been delivered for the timer, the return value of
181 .Fn timer_getoverrun
182 is unspecified.
183 .Sh RETURN VALUES
184 If the
185 .Fn timer_getoverrun
186 system call succeeds, it returns the timer expiration overrun count as explained
187 above.
188 Otherwise the value \-1 is returned, and the global variable
189 .Va errno
190 is set to indicate the error.
191 .Pp
192 .Rv -std timer_gettime timer_settime
193 .Sh ERRORS
194 The
195 .Fn timer_settime
196 system call
197 will fail if:
198 .Bl -tag -width Er
199 .It Bq Er EINVAL
200 A
201 .Fa value
202 structure specified a nanosecond value less than zero or greater than
203 or equal to 1000 million, and the
204 .Va it_value
205 member of that structure did not
206 specify zero seconds and nanoseconds.
207 .El
208 .Pp
209 These system calls may fail if:
210 .Bl -tag -width Er
211 .It Bq Er EINVAL
212 The
213 .Fa timerid
214 argument does not correspond to an ID returned by
215 .Fn timer_create
216 but not yet deleted by
217 .Fn timer_delete .
218 .El
219 .Pp
220 The
221 .Fn timer_settime
222 system call may fail if:
223 .Bl -tag -width Er
224 .It Bq Er EINVAL
225 The
226 .Va it_interval
227 member of
228 .Fa value
229 is not zero and the timer was created with
230 notification by creation of a new thread
231 .Va ( sigev_sigev_notify
232 was
233 .Dv SIGEV_THREAD )
234 and a fixed stack address has been set in the thread attribute pointed to by
235 .Va sigev_notify_attributes .
236 .El
237 .Pp
238 The
239 .Fn timer_gettime
240 and
241 .Fn timer_settime
242 system calls
243 may fail if:
244 .Bl -tag -width Er
245 .It Bq Er EFAULT
246 Any arguments point outside the allocated address space or there is a
247 memory protection fault.
248 .El
249 .Sh SEE ALSO
250 .Xr clock_getres 2 ,
251 .Xr timer_create 2 ,
252 .Xr siginfo 3
253 .Sh STANDARDS
254 The
255 .Fn timer_getoverrun ,
256 .Fn timer_gettime ,
257 and
258 .Fn timer_settime
259 system calls conform to
260 .St -p1003.1-2004 .
261 .Sh HISTORY
262 Support for
263 .Tn POSIX
264 per-process timer first appeared in
265 .Fx 7.0 .