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: sleep.9,v 1.8 1997/04/09 05:39:32 mpp Exp $ 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.Ft int 41.Fn tsleep "void *ident" "int priority" "char *wmesg" "int timo" 42.Ft void 43.Fn wakeup "void *ident" 44.Ft void 45.Fn wakeup_one "void *ident" 46.Sh DESCRIPTION 47The functions 48.Fn tsleep 49and 50.Fn wakeup 51handle event-based process blocking. If a process must wait for an 52external event, it is put on sleep by 53.Nm tsleep . 54The parameter 55.Ar ident 56is an arbitrary address that uniquely identifies the event on which 57the process is being asleep. All processes sleeping on a single 58.Ar ident 59are woken up later by 60.Nm wakeup , 61often called from inside an interrupt routine, to indicate that the 62resource the process was blocking on is available now. 63.Pp 64The parameter 65.Ar wmesg 66is a string describing the sleep condition for tools like 67.Xr ps 1 . 68Due to the limited space of those programs to display arbitrary strings, 69this message should not be longer than 6 characters. 70.Pp 71The 72.Fn wakeup_one 73function is used to make the first process in the queue that is 74sleeping on the parameter 75.Fa ident 76runnable. This can prevent the system from becoming saturated 77when a large number of processes are sleeping on the same address, 78but only one of them can actually do any useful work when made 79runnable. 80.Pp 81.Nm Tsleep 82is the general sleep call. Suspends the current process until a wakeup is 83performed on the specified identifier. The process will then be made 84runnable with the specified 85.Ar priority . 86Sleeps at most 87.Ar timo 88\&/ hz seconds (0 means no timeout). If 89.Ar pri 90includes the 91.Dv PCATCH 92flag, signals are checked before and after sleeping, else signals are 93not checked. Returns 0 if awakened, 94.Dv EWOULDBLOCK 95if the timeout expires. If 96.Dv PCATCH 97is set and a signal needs to be delivered, 98.Dv ERESTART 99is returned if the current system call should be restarted if 100possible, and 101.Dv EINTR 102is returned if the system call should be interrupted by the signal 103.Pq return Dv EINTR . 104.Pp 105.Nm Sleep 106is the traditional form. It doesn't let you specify a timeout nor a 107.Ar wmesg , 108hence its use is deprecated. 109.Sh RETURN VALUES 110See above. 111.Sh SEE ALSO 112.Xr ps 1 113.Sh HISTORY 114The sleep/wakeup process synchronization mechanism is very old. It 115appeared in a very early version of Unix. 116.Pp 117.Nm Tsleep 118appeared in 119.Bx 4.4 . 120.Sh AUTHORS 121This man page has been written by 122.ie t J\(:org Wunsch. 123.el Joerg Wunsch. 124