xref: /openbsd/lib/libc/gen/sleep.3 (revision d415bd75)
1.\"	$OpenBSD: sleep.3,v 1.18 2022/03/31 17:27:15 naddy 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.Dd $Mdocdate: March 31 2022 $
31.Dt SLEEP 3
32.Os
33.Sh NAME
34.Nm sleep
35.Nd suspend execution for an interval of seconds
36.Sh SYNOPSIS
37.In unistd.h
38.Ft unsigned int
39.Fn sleep "unsigned int seconds"
40.Sh DESCRIPTION
41The
42.Fn sleep
43function suspends execution of the calling thread until at least the
44given number of
45.Fa seconds
46have elapsed or an unmasked signal is delivered to the calling thread.
47.Pp
48This version of
49.Fn sleep
50is implemented with
51.Xr nanosleep 2 ,
52so delivery of any unmasked signal will terminate the sleep early,
53even if
54.Dv SA_RESTART
55is set with
56.Xr sigaction 2
57for the interrupting signal.
58.Sh RETURN VALUES
59If
60.Fn sleep
61sleeps for the full count of
62.Fa seconds ,
63it returns 0.
64Otherwise,
65.Fn sleep
66returns the number of seconds remaining from the original request.
67.Sh ERRORS
68The
69.Fn sleep
70function sets
71.Va errno
72to
73.Dv EINTR
74if it is interrupted by the delivery of a signal.
75.Sh SEE ALSO
76.Xr sleep 1 ,
77.Xr nanosleep 2 ,
78.Xr sigaction 2
79.Sh STANDARDS
80The
81.Fn sleep
82function conforms to
83.St -p1003.1-2008 .
84.Pp
85Setting
86.Va errno
87is an extension to that specification.
88.Sh HISTORY
89A
90.Fn sleep
91system call first appeared in
92.At v2 .
93In
94.At v7 ,
95it was removed and replaced by a C library implementation based on
96.Xr signal 3
97and
98.Xr alarm 3 .
99For
100.Ox 2.1 ,
101it was reimplemented as a wrapper around the
102.Xr nanosleep 2
103system call.
104