xref: /freebsd/lib/libsys/sigwait.2 (revision 1edb7116f450c1a1793f2fd25f6bdc16735ef888)
1.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice(s), this list of conditions and the following disclaimer as
9.\"    the first lines of this file unmodified other than the possible
10.\"    addition of one or more copyright notices.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice(s), this list of conditions and the following disclaimer in
13.\"    the documentation and/or other materials provided with the
14.\"    distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.Dd September 6, 2013
29.Dt SIGWAIT 2
30.Os
31.Sh NAME
32.Nm sigwait
33.Nd select a set of signals
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In signal.h
38.Ft int
39.Fn sigwait "const sigset_t * restrict set" "int * restrict sig"
40.Sh DESCRIPTION
41The
42.Fn sigwait
43system call selects a set of signals, specified by
44.Fa set .
45If none of the selected signals are pending,
46.Fn sigwait
47waits until one or more of the selected signals has been generated.
48Then
49.Fn sigwait
50atomically clears one of the selected signals from the set of pending signals
51(for the process or for the current thread) and sets the location pointed to by
52.Fa sig
53to the signal number that was cleared.
54.Pp
55The signals specified by
56.Fa set
57should be blocked at the time of the call to
58.Fn sigwait .
59.Pp
60If more than one thread is using
61.Fn sigwait
62to wait for the same signal, no more than one of these threads will return from
63.Fn sigwait
64with the signal number.
65If more than a single thread is blocked in
66.Fn sigwait
67for a signal when that signal is generated for the process, it is unspecified
68which of the waiting threads returns from
69.Fn sigwait .
70If the signal is generated for a specific thread, as by
71.Fn pthread_kill ,
72only that thread will return.
73.Pp
74Should any of the multiple pending signals in the range
75.Dv SIGRTMIN
76to
77.Dv SIGRTMAX
78be
79selected, it will be the lowest numbered one.
80The selection order between realtime
81and non-realtime signals, or between multiple pending non-realtime signals,
82is unspecified.
83.Sh IMPLEMENTATION NOTES
84The
85.Fn sigwait
86function is implemented as a wrapper around the
87.Fn __sys_sigwait
88system call, which retries the call on
89.Er EINTR
90error.
91.Sh RETURN VALUES
92If successful,
93.Fn sigwait
94returns 0 and sets the location pointed to by
95.Fa sig
96to the cleared signal number.
97Otherwise, an error number is returned.
98.Sh ERRORS
99The
100.Fn sigwait
101system call will fail if:
102.Bl -tag -width Er
103.It Bq Er EINVAL
104The
105.Fa set
106argument
107specifies one or more invalid signal numbers.
108.El
109.Sh SEE ALSO
110.Xr sigaction 2 ,
111.Xr sigpending 2 ,
112.Xr sigqueue 2 ,
113.Xr sigsuspend 2 ,
114.Xr sigtimedwait 2 ,
115.Xr sigwaitinfo 2 ,
116.Xr pause 3 ,
117.Xr pthread_sigmask 3
118.Sh STANDARDS
119The
120.Fn sigwait
121function conforms to
122.St -p1003.1-96 .
123