1SIGWAIT(3P) POSIX Programmer's Manual SIGWAIT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 sigwait — wait for queued signals
14
16 #include <signal.h>
17
18 int sigwait(const sigset_t *restrict set, int *restrict sig);
19
21 The sigwait() function shall select a pending signal from set, atomi‐
22 cally clear it from the system's set of pending signals, and return
23 that signal number in the location referenced by sig. If prior to the
24 call to sigwait() there are multiple pending instances of a single sig‐
25 nal number, it is implementation-defined whether upon successful return
26 there are any remaining pending signals for that signal number. If the
27 implementation supports queued signals and there are multiple signals
28 queued for the signal number selected, the first such queued signal
29 shall cause a return from sigwait() and the remainder shall remain
30 queued. If no signal in set is pending at the time of the call, the
31 thread shall be suspended until one or more becomes pending. The sig‐
32 nals defined by set shall have been blocked at the time of the call to
33 sigwait(); otherwise, the behavior is undefined. The effect of sig‐
34 wait() on the signal actions for the signals in set is unspecified.
35
36 If more than one thread is using sigwait() to wait for the same signal,
37 no more than one of these threads shall return from sigwait() with the
38 signal number. If more than a single thread is blocked in sigwait() for
39 a signal when that signal is generated for the process, it is unspeci‐
40 fied which of the waiting threads returns from sigwait(). If the sig‐
41 nal is generated for a specific thread, as by pthread_kill(), only that
42 thread shall return.
43
44 Should any of the multiple pending signals in the range SIGRTMIN to
45 SIGRTMAX be selected, it shall be the lowest numbered one. The selec‐
46 tion order between realtime and non-realtime signals, or between multi‐
47 ple pending non-realtime signals, is unspecified.
48
50 Upon successful completion, sigwait() shall store the signal number of
51 the received signal at the location referenced by sig and return zero.
52 Otherwise, an error number shall be returned to indicate the error.
53
55 The sigwait() function may fail if:
56
57 EINVAL The set argument contains an invalid or unsupported signal num‐
58 ber.
59
60 The following sections are informative.
61
63 None.
64
66 None.
67
69 To provide a convenient way for a thread to wait for a signal, this
70 volume of POSIX.1‐2008 provides the sigwait() function. For most cases
71 where a thread has to wait for a signal, the sigwait() function should
72 be quite convenient, efficient, and adequate.
73
74 However, requests were made for a lower-level primitive than sigwait()
75 and for semaphores that could be used by threads. After some considera‐
76 tion, threads were allowed to use semaphores and sem_post() was defined
77 to be async-signal-safe.
78
79 In summary, when it is necessary for code run in response to an asyn‐
80 chronous signal to notify a thread, sigwait() should be used to handle
81 the signal. Alternatively, if the implementation provides semaphores,
82 they also can be used, either following sigwait() or from within a sig‐
83 nal handling routine previously registered with sigaction().
84
86 None.
87
89 Section 2.4, Signal Concepts, Section 2.8.1, Realtime Signals, pause(),
90 pthread_sigmask(), sigaction(), sigpending(), sigsuspend(), sigtimed‐
91 wait()
92
93 The Base Definitions volume of POSIX.1‐2008, <signal.h>, <time.h>
94
96 Portions of this text are reprinted and reproduced in electronic form
97 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
98 -- Portable Operating System Interface (POSIX), The Open Group Base
99 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
100 cal and Electronics Engineers, Inc and The Open Group. (This is
101 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
102 event of any discrepancy between this version and the original IEEE and
103 The Open Group Standard, the original IEEE and The Open Group Standard
104 is the referee document. The original Standard can be obtained online
105 at http://www.unix.org/online.html .
106
107 Any typographical or formatting errors that appear in this page are
108 most likely to have been introduced during the conversion of the source
109 files to man page format. To report such errors, see https://www.ker‐
110 nel.org/doc/man-pages/reporting_bugs.html .
111
112
113
114IEEE/The Open Group 2013 SIGWAIT(3P)