1sigwait(2) System Calls sigwait(2)
2
3
4
6 sigwait - wait until a signal is posted
7
9 #include <signal.h>
10
11 int sigwait(sigset_t *set);
12
13
14 Standard conforming
15 cc [ flag ... ] file ... -D_POSIX_PTHREAD_SEMANTICS [ library...]
16 #include <signal.h>
17
18 int sigwait(const sigset_t *set, int *sig);
19
20
22 The sigwait() function selects a signal in set that is pending on the
23 calling thread. If no signal in set is pending, sigwait() blocks until
24 a signal in set becomes pending. The selected signal is cleared from
25 the set of signals pending on the calling thread and the number of the
26 signal is returned, or in the standard-conforming version (see stan‐
27 dards(5)) placed in sig. The selection of a signal in set is indepen‐
28 dent of the signal mask of the calling thread. This means a thread can
29 synchronously wait for signals that are being blocked by the signal
30 mask of the calling thread . To ensure that only the caller receives
31 the signals defined in set, all threads should have signals in set
32 masked including the calling thread.
33
34
35 If more than one thread is using sigwait() to wait for the same signal,
36 no more than one of these threads returns from sigwait() with the sig‐
37 nal number. If more than a single thread is blocked in sigwait() for a
38 signal when that signal is generated for the process, it is unspecified
39 which of the waiting threads returns from sigwait(). If the signal is
40 generated for a specific thread, as by pthread_kill(3C), only that
41 thread returns.
42
43
44 Should any of the multiple pending signals in the range SIGRTMIN to
45 SIGRTMAX be selected, it will be the lowest numbered one. The selection
46 order between realtime and non-realtime signals, or between multiple
47 pending non-realtime signals, is unspecified.
48
50 Upon successful completion, the default version of sigwait() returns a
51 signal number; the standard-conforming version returns 0 and stores the
52 received signal number at the location pointed to by sig. Otherwise,
53 the default version returns -1 and sets errno to indicate an error; the
54 standard-conforming version returns an error number to indicate the
55 error.
56
58 The sigwait() function will fail if:
59
60 EFAULT The set argument points to an invalid address.
61
62
63 EINTR The wait was interrupted by an unblocked, caught signal.
64
65
66 EINVAL The set argument contains an unsupported signal number.
67
68
70 Example 1 Creating a thread to handle receipt of a signal
71
72
73 The following sample C code creates a thread to handle the receipt of a
74 signal. More specifically, it catches the asynchronously generated sig‐
75 nal, SIGINT.
76
77
78 /********************************************************************
79 *
80 * compile with -D_POSIX_PTHREAD_SEMANTICS switch;
81