xref: /openbsd/lib/libc/gen/usleep.3 (revision 404b540a)
1.\"	$OpenBSD: usleep.3,v 1.17 2008/10/24 14:34:39 jmc 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: October 24 2008 $
31.Dt USLEEP 3
32.Os
33.Sh NAME
34.Nm usleep
35.Nd suspend execution for interval of microseconds
36.Sh SYNOPSIS
37.Fd #include <unistd.h>
38.Ft int
39.Fn usleep "useconds_t microseconds"
40.Sh DESCRIPTION
41The
42.Fn usleep
43function suspends execution of the calling process for
44.Fa microseconds
45microseconds of time.
46System activity or time spent in processing the
47call may lengthen the sleep slightly.
48.Pp
49This routine is implemented using
50.Xr nanosleep 2 ;
51it requires one system call each time it is invoked.
52A similar but less compatible function can be obtained with a single
53.Xr select 2 ;
54such a function would not restart after signals, and also does not interfere
55with other uses of
56.Xr setitimer 2
57(not that
58.Fn usleep
59interferes with interval timers anymore).
60.Sh RETURN VALUES
61If the
62.Fn usleep
63function returns because the requested time has elapsed, the value
64returned will be zero.
65.Pp
66If the
67.Fn usleep
68function returns due to the delivery of a signal, the value returned
69will be \-1, and the global variable
70.Va errno
71will be set to indicate the interruption.
72.Sh ERRORS
73If any of the following conditions occur, the
74.Fn usleep
75function shall return \-1 and set
76.Va errno
77to the corresponding value.
78.Bl -tag -width Er
79.It Bq Er EINTR
80.Fn usleep
81was interrupted by the delivery of a signal.
82.It Bq Er EINVAL
83.Fa microseconds
84specified a value of 1,000,000 or more microseconds.
85.El
86.Sh NOTES
87A microsecond is 0.000001 seconds.
88.Sh SEE ALSO
89.Xr sleep 1 ,
90.Xr getitimer 2 ,
91.Xr nanosleep 2 ,
92.Xr setitimer 2 ,
93.Xr alarm 3 ,
94.Xr sigpause 3 ,
95.Xr sleep 3 ,
96.Xr ualarm 3
97.Sh STANDARDS
98The
99.Fn usleep
100function conforms to
101.St -xpg4.2 .
102.Sh HISTORY
103The
104.Fn usleep
105function appeared in
106.Bx 4.3 .
107