xref: /freebsd/share/man/man9/sleep.9 (revision b5b2a90624d3d900a42e99758eb95293d04f37fa)
1.\"
2.\" Copyright (c) 1996 Joerg Wunsch
3.\"
4.\" 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.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.\" $Id$
27.\" "
28.Dd April 3, 1996
29.Os
30.Dt SLEEP 9
31.Sh NAME
32.Nm sleep ,
33.Nm tsleep ,
34.Nm wakeup
35.Nd wait for events
36.Sh SYNOPSIS
37.Fd #include <sys/param.h>
38.Fd #include <sys/systm.h>
39.Fd #include <sys/proc.h>
40.Fd #include <sys/errno.h>
41.Ft int
42.Fn tsleep "void *ident" "int priority" "char *wmesg" "int timo"
43.Ft void
44.Fn wakeup "void *ident"
45.Ft int
46.Fn sleep "void *ident" "int priority"
47.Sh DESCRIPTION
48The functions
49.Fn tsleep
50and
51.Fn wakeup
52handle event-based process blocking.  If a process must wait for an
53external event, it is put on sleep by
54.Nm tsleep .
55The parameter
56.Ar ident
57is an arbitrary address that uniquely identifies the event on which
58the process is being asleep.  All processes sleeping on a single
59.Ar ident
60are woken up later by
61.Nm wakeup ,
62often called from inside an interrupt routine, to indicate that the
63resource the process was blocking on is available now.
64.Pp
65The parameter
66.Ar wmesg
67is a string describing the sleep condition for tools like
68.Xr ps 1 .
69Due to the limited space of those programs to display arbitrary strings,
70this message should not be longer than 6 characters.
71.Pp
72.Nm Tsleep
73is the general sleep call.  Suspends the current process until a wakeup is
74performed on the specified identifier.  The process will then be made
75runnable with the specified
76.Ar priority .
77Sleeps at most
78.Ar timo
79\&/ hz seconds (0 means no timeout).  If
80.Ar pri
81includes the
82.Dv PCATCH
83flag, signals are checked before and after sleeping, else signals are
84not checked.  Returns 0 if awakened,
85.Dv EWOULDBLOCK
86if the timeout expires.  If
87.Dv PCATCH
88is set and a signal needs to be delivered,
89.Dv ERESTART
90is returned if the current system call should be restarted if
91possible, and
92.Dv EINTR
93is returned if the system call should be interrupted by the signal
94.Pq return Dv EINTR .
95.Pp
96.Nm Sleep
97is the traditional form.  It doesn't let you specify a timeout nor a
98.Ar wmesg ,
99hence its use is deprecated.
100.Sh RETURN VALUES
101See above.
102.Sh SEE ALSO
103.Xr ps 1
104.Sh HISTORY
105The sleep/wakeup process synchronization mechanism is very old.  It
106appeared in a very early version of Unix.
107.Pp
108.Nm Tsleep
109appeared in
110.Bx 4.4 .
111.Sh AUTHORS
112This man page has been written by
113.ie t J\(:org Wunsch.
114.el Joerg Wunsch.
115