xref: /openbsd-src/lib/libc/sys/nanosleep.2 (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1.\"	$OpenBSD: nanosleep.2,v 1.15 2015/05/31 23:54:25 schwarze 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: May 31 2015 $
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 1000 million,
80or a second value less than zero or greater than 100 million.
81.It Bq Er EFAULT
82Either
83.Fa timeout
84or
85.Fa remainder
86points to memory that is not a valid part of the process address space.
87.El
88.Sh SEE ALSO
89.Xr sleep 1 ,
90.Xr sleep 3
91.Sh STANDARDS
92The
93.Fn nanosleep
94function conforms to
95.St -p1003.1-2008 .
96.Sh HISTORY
97The predecessor of this system call,
98.Fn sleep ,
99appeared in
100.At v3 ,
101but was removed when
102.Xr alarm 3
103was introduced into
104.At v7 .
105The
106.Fn nanosleep
107system call has been available since
108.Nx 1.3
109and was ported to
110.Ox 2.1
111and
112.Fx 3.0 .
113