xref: /minix/lib/libc/sys/nanosleep.2 (revision 0a6a1f1d)
1.\"	$NetBSD: nanosleep.2,v 1.17 2015/10/02 19:52:49 christos 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.\"
32.Dd October 2, 2015
33.Dt NANOSLEEP 2
34.Os
35.Sh NAME
36.Nm nanosleep
37.Nd high resolution sleep
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In time.h
42.Ft int
43.Fn clock_nanosleep "clockid_t clock_id" "int flags" "const struct timespec *rqtp" "struct timespec *rmtp"
44.Ft int
45.Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp"
46.Sh DESCRIPTION
47If the
48.Dv TIMER_ABSTIME
49flag is not set in the
50.Fa flags
51argument, then
52.Fn clock_nanosleep
53suspends execution of the calling thread until either the number of
54seconds and nanoseconds specified in the
55.Fa rqtp
56argument have elapsed using the clock in the
57.Fa clock_id
58argument, or a signal is delivered to the calling process and its
59action is to invoke a signal catching function or to terminate the
60process.
61.Pp
62If the
63.Dv TIMER_ABSTIME
64flag is set in the
65.Fa flags
66argument, then
67.Fn clock_nanosleep
68suspends execution of the calling thread until either the value
69of the clock specified in the
70.Fa clock_id
71argument reaches the value of the
72.Fa rqtp
73argument in seconds and nanoseconds,
74or a signal is delivered to the calling process and its
75action is to invoke a signal catching function or to terminate the
76process.
77.Pp
78The suspension time may be longer than requested due to the
79scheduling of other activity by the system.
80.Pp
81The
82.Fn nanosleep
83function behaves like
84.Fn clock_nanosleep
85with the
86.Fa clock_id
87argument equal to
88.Dv CLOCK_MONOTONIC
89and the
90.Fa flags
91argument having
92.Dv TIMER_ABSTIME
93not set.
94.Pp
95The
96.Em struct timespec
97is described in
98.Xr timespec 3 .
99The
100.Fa clock_id
101specified is the time source.
102.Sh RETURN VALUES
103If the
104.Fn clock_nanosleep
105or the
106.Fn nanosleep
107functions return because the requested time has elapsed, the value
108returned will be zero.
109.Pp
110If the
111.Fn clock_nanosleep
112or the
113.Fn nanosleep
114functions return due to the delivery of a signal, then
115.Fn clock_nanosleep
116will return directly the error number, and
117.Fn nanosleep
118will return \-1, and the global variable
119.Va errno
120will be set to indicate the interruption.
121If
122.Fa rmtp
123is
124.Pf non- Dv NULL ,
125the timespec structure it references is updated to contain the
126unslept amount (the request time minus the time actually slept).
127.Sh ERRORS
128If any of the following conditions occur, the
129.Fn nanosleep
130function shall return \-1 and set
131.Va errno
132to the corresponding value, and the
133.Fn clock_nanosleep
134function shall return the errnor number directly.
135.Bl -tag -width Er
136.It Bq Er EFAULT
137Either
138.Fa rqtp
139or
140.Fa rmtp
141points to memory that is not a valid part of the process
142address space.
143.It Bq Er EINTR
144.Nm
145was interrupted by the delivery of a signal.
146.It Bq Er EINVAL
147.Fa rqtp
148specified a nanosecond value less than zero or greater than 1000 million.
149.It Bq Er ENOSYS
150.Nm
151is not supported by this implementation.
152.It Bq Er ENOTSUP
153for
154.Fn clock_nanosleep ,
155the clock specified in the
156.Fa clock_id
157argument is not supported.
158.El
159.Sh SEE ALSO
160.Xr sleep 3 ,
161.Xr timespec 3
162.Sh STANDARDS
163The
164.Fn nanosleep
165function conforms to
166.St -p1003.1b-93 .
167The
168.Fn clock_nanosleep
169function conforms to
170.St -p1003.1j-2000 .
171.Sh BUGS
172The
173.Nx
174kernel is not tickless, so the maximum sleep resolution is determined
175by the value of
176.Dv HZ
177which is by default
178.Dv 100
179in most architectures.
180This means that a request to sleep for less than
181.Dv 10ms
182(1 /
183.Dv HZ
184seconds), is rounded up to that.
185