xref: /openbsd/lib/libc/sys/nanosleep.2 (revision 3cab2bb3)
1.\"	$OpenBSD: nanosleep.2,v 1.16 2018/12/31 18:54:00 cheloha Exp $
2.\"	$NetBSD: nanosleep.2,v 1.1 1997/04/17 18:12:02 jtc Exp $
3.\"
4.\" Copyright (c) 1986, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)sleep.3	8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: December 31 2018 $
34.Dt NANOSLEEP 2
35.Os
36.Sh NAME
37.Nm nanosleep
38.Nd high resolution sleep
39.Sh SYNOPSIS
40.In time.h
41.Ft int
42.Fn nanosleep "const struct timespec *timeout" "struct timespec *remainder"
43.Sh DESCRIPTION
44.Fn nanosleep
45suspends execution of the calling process for the duration specified by
46.Fa timeout .
47An unmasked signal will cause it to terminate the sleep early,
48regardless of the
49.Dv SA_RESTART
50value on the interrupting signal.
51.Sh RETURN VALUES
52If the
53.Fn nanosleep
54function returns because the requested duration has elapsed, the value
55returned will be zero.
56.Pp
57If the
58.Fn nanosleep
59function returns due to the delivery of a signal, the value returned
60will be \-1, and the global variable
61.Va errno
62will be set to indicate the interruption.
63If
64.Fa remainder
65is non-null, the timespec structure it references is updated to contain the
66unslept amount (the requested duration minus the duration actually slept).
67.Sh ERRORS
68If any of the following conditions occur, the
69.Fn nanosleep
70function shall return \-1 and set
71.Va errno
72to the corresponding value.
73.Bl -tag -width Er
74.It Bq Er EINTR
75.Fn nanosleep
76was interrupted by the delivery of a signal.
77.It Bq Er EINVAL
78.Fa timeout
79specified a nanosecond value less than zero or greater than or equal to
801000 million,
81or a second value less than zero.
82.It Bq Er EFAULT
83Either
84.Fa timeout
85or
86.Fa remainder
87points to memory that is not a valid part of the process address space.
88.El
89.Sh SEE ALSO
90.Xr sleep 1 ,
91.Xr sleep 3
92.Sh STANDARDS
93The
94.Fn nanosleep
95function conforms to
96.St -p1003.1-2008 .
97.Sh HISTORY
98The predecessor of this system call,
99.Fn sleep ,
100appeared in
101.At v3 ,
102but was removed when
103.Xr alarm 3
104was introduced into
105.At v7 .
106The
107.Fn nanosleep
108system call has been available since
109.Nx 1.3
110and was ported to
111.Ox 2.1
112and
113.Fx 3.0 .
114