]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/nanosleep.2
libarchive: merge vendor bugfixes
[FreeBSD/FreeBSD.git] / lib / libc / sys / nanosleep.2
1 .\"     $NetBSD: nanosleep.2,v 1.23 2016/11/14 10:40:59 wiz Exp $
2 .\"
3 .\" Copyright (c) 1986, 1991, 1993
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\"    may be used to endorse or promote products derived from this software
16 .\"    without specific prior written permission.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" SUCH DAMAGE.
29 .\"
30 .\"     @(#)sleep.3     8.1 (Berkeley) 6/4/93
31 .\" $FreeBSD$
32 .\"
33 .Dd October 7, 2021
34 .Dt NANOSLEEP 2
35 .Os
36 .Sh NAME
37 .Nm nanosleep
38 .Nd high resolution sleep
39 .Sh LIBRARY
40 .Lb libc
41 .Sh SYNOPSIS
42 .In time.h
43 .Ft int
44 .Fo clock_nanosleep
45 .Fa "clockid_t clock_id"
46 .Fa "int flags"
47 .Fa "const struct timespec *rqtp"
48 .Fa "struct timespec *rmtp"
49 .Fc
50 .Ft int
51 .Fo nanosleep
52 .Fa "const struct timespec *rqtp"
53 .Fa "struct timespec *rmtp"
54 .Fc
55 .Sh DESCRIPTION
56 If the
57 .Dv TIMER_ABSTIME
58 flag is not set in the
59 .Fa flags
60 argument, then
61 .Fn clock_nanosleep
62 suspends execution of the calling thread until either the
63 time interval specified by the
64 .Fa rqtp
65 argument has elapsed,
66 or a signal is delivered to the calling process and its
67 action is to invoke a signal-catching function or to terminate the
68 process.
69 The clock used to measure the time is specified by the
70 .Fa clock_id
71 argument.
72 .Pp
73 If the
74 .Dv TIMER_ABSTIME
75 flag is set in the
76 .Fa flags
77 argument, then
78 .Fn clock_nanosleep
79 suspends execution of the calling thread until either the value
80 of the clock specified by the
81 .Fa clock_id
82 argument reaches the absolute time specified by the
83 .Fa rqtp
84 argument,
85 or a signal is delivered to the calling process and its
86 action is to invoke a signal-catching function or to terminate the
87 process.
88 If, at the time of the call, the time value specified by
89 .Fa rqtp
90 is less than or equal to the time value of the specified clock, then
91 .Fn clock_nanosleep
92 returns immediately and the calling thread is not suspended.
93 .Pp
94 The suspension time may be longer than requested due to the
95 scheduling of other activity by the system.
96 It is also subject to the allowed time interval deviation
97 specified by the
98 .Va kern.timecounter.alloweddeviation
99 .Xr sysctl 8
100 variable.
101 An unmasked signal will terminate the sleep early, regardless of the
102 .Dv SA_RESTART
103 value on the interrupting signal.
104 The
105 .Fa rqtp
106 and
107 .Fa rmtp
108 arguments can point to the same object.
109 .Pp
110 The following
111 .Fa clock_id
112 values are supported:
113 .Pp
114 .Bl -item -compact -offset indent
115 .It
116 CLOCK_MONOTONIC
117 .It
118 CLOCK_MONOTONIC_FAST
119 .It
120 CLOCK_MONOTONIC_PRECISE
121 .It
122 CLOCK_REALTIME
123 .It
124 CLOCK_REALTIME_FAST
125 .It
126 CLOCK_REALTIME_PRECISE
127 .It
128 CLOCK_SECOND
129 .It
130 CLOCK_UPTIME
131 .It
132 CLOCK_UPTIME_FAST
133 .It
134 CLOCK_UPTIME_PRECISE
135 .El
136 .Pp
137 The
138 .Fn nanosleep
139 function behaves like
140 .Fn clock_nanosleep
141 with a
142 .Fa clock_id
143 argument of
144 .Dv CLOCK_REALTIME
145 and without the
146 .Dv TIMER_ABSTIME
147 flag in the
148 .Fa flags
149 argument.
150 .Sh RETURN VALUES
151 These functions return zero when the requested time has elapsed.
152 .Pp
153 If these functions return for any other reason, then
154 .Fn clock_nanosleep
155 will directly return the error number, and
156 .Fn nanosleep
157 will return \-1 with the global variable
158 .Va errno
159 set to indicate the error.
160 If a relative sleep is interrupted by a signal and
161 .Fa rmtp
162 is
163 .Pf non- Dv NULL ,
164 the timespec structure it references is updated to contain the
165 unslept amount (the request time minus the time actually slept).
166 .Sh ERRORS
167 These functions can fail with the following errors.
168 .Bl -tag -width Er
169 .It Bq Er EFAULT
170 Either
171 .Fa rqtp
172 or
173 .Fa rmtp
174 points to memory that is not a valid part of the process
175 address space.
176 .It Bq Er EINTR
177 The function was interrupted by the delivery of a signal.
178 .It Bq Er EINVAL
179 The
180 .Fa rqtp
181 argument specified a nanosecond value less than zero
182 or greater than or equal to 1000 million.
183 .It Bq Er EINVAL
184 The
185 .Fa flags
186 argument contained an invalid flag.
187 .It Bq Er EINVAL
188 The
189 .Fa clock_id
190 argument was
191 .Dv CLOCK_THREAD_CPUTIME_ID
192 or an unrecognized value.
193 .It Bq Er ENOTSUP
194 The
195 .Fa clock_id
196 argument was valid but not supported by this implementation of
197 .Fn clock_nanosleep .
198 .El
199 .Sh SEE ALSO
200 .Xr clock_gettime 2 ,
201 .Xr sigaction 2 ,
202 .Xr sleep 3
203 .Sh STANDARDS
204 These functions conform to
205 .St -p1003.1-2008 .