xref: /openbsd-src/lib/libc/sys/nanosleep.2 (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1.\"	$OpenBSD: nanosleep.2,v 1.11 2008/10/24 14:34:39 jmc 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: October 24 2008 $
34.Dt NANOSLEEP 2
35.Os
36.Sh NAME
37.Nm nanosleep
38.Nd high resolution sleep
39.Sh SYNOPSIS
40.Fd #include <time.h>
41.Ft int
42.Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp"
43.Sh DESCRIPTION
44.Fn nanosleep
45suspends execution of the calling process for the time specified.
46An unmasked signal will cause it to terminate the sleep early,
47regardless of the
48.Dv SA_RESTART
49value on the interrupting signal.
50.Sh RETURN VALUES
51If the
52.Fn nanosleep
53function returns because the requested time has elapsed, the value
54returned will be zero.
55.Pp
56If the
57.Fn nanosleep
58function returns due to the delivery of a signal, the value returned
59will be \-1, and the global variable
60.Va errno
61will be set to indicate the interruption.
62If
63.Fa rmtp
64is non-null, the timespec structure it references is updated to contain the
65unslept amount (the request time minus the time actually slept).
66.Sh ERRORS
67If any of the following conditions occur, the
68.Fn nanosleep
69function shall return \-1 and set
70.Va errno
71to the corresponding value.
72.Bl -tag -width Er
73.It Bq Er EFAULT
74Either
75.Fa rqtp
76or
77.Fa rmtp
78points to memory that is not a valid part of the process address space.
79.It Bq Er EINTR
80.Nm
81was interrupted by the delivery of a signal.
82.It Bq Er EINVAL
83.Fa rqtp
84specified a nanosecond value less than zero or greater than 1000 million,
85or a second value less than zero or greater than 100 million.
86.It Bq Er ENOSYS
87.Nm
88is not supported by this implementation.
89.El
90.Sh SEE ALSO
91.Xr sleep 1 ,
92.Xr sleep 3
93.Sh STANDARDS
94The
95.Fn nanosleep
96function conforms to
97.St -p1003.1b-93 .
98