2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
4 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
5 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SIGWAIT 2 "Apr 16, 2009"
8 sigwait \- wait until a signal is posted
14 \fBint\fR \fBsigwait\fR(\fBsigset_t *\fR\fIset\fR);
17 .SS "Standard conforming"
20 cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-D_POSIX_PTHREAD_SEMANTICS\fR [ \fIlibrary\fR...]
23 \fBint\fR \fBsigwait\fR(\fBconst sigset_t *\fR\fIset\fR, \fBint *\fR\fIsig\fR);
29 The \fBsigwait()\fR function selects a signal in \fIset\fR that is pending on
30 the calling thread. If no signal in \fIset\fR is pending, \fBsigwait()\fR
31 blocks until a signal in \fIset\fR becomes pending. The selected signal is
32 cleared from the set of signals pending on the calling thread and the number of
33 the signal is returned, or in the standard-conforming version (see
34 \fBstandards\fR(5)) placed in \fIsig\fR. The selection of a signal in \fIset\fR
35 is independent of the signal mask of the calling thread. This means a thread
36 can synchronously wait for signals that are being blocked by the signal mask of
37 the calling thread \&. To ensure that only the caller receives the signals
38 defined in \fIset\fR, all threads should have signals in \fIset\fR masked
39 including the calling thread.
42 If more than one thread is using \fBsigwait()\fR to wait for the same signal,
43 no more than one of these threads returns from \fBsigwait()\fR with the signal
44 number. If more than a single thread is blocked in \fBsigwait()\fR for a signal
45 when that signal is generated for the process, it is unspecified which of the
46 waiting threads returns from \fBsigwait()\fR. If the signal is generated for a
47 specific thread, as by \fBpthread_kill\fR(3C), only that thread returns.
50 Should any of the multiple pending signals in the range \fBSIGRTMIN\fR to
51 \fBSIGRTMAX\fR be selected, it will be the lowest numbered one. The selection
52 order between realtime and non-realtime signals, or between multiple pending
53 non-realtime signals, is unspecified.
57 Upon successful completion, the default version of \fBsigwait()\fR returns a
58 signal number; the standard-conforming version returns \fB0\fR and stores the
59 received signal number at the location pointed to by \fIsig\fR. Otherwise, the
60 default version returns -1 and sets errno to indicate an error; the
61 standard-conforming version returns an error number to indicate the error.
65 The \fBsigwait()\fR function will fail if:
72 The \fIset\fR argument points to an invalid address.
81 The wait was interrupted by an unblocked, caught signal.
90 The \fIset\fR argument contains an unsupported signal number.
95 \fBExample 1 \fRCreating a thread to handle receipt of a signal
98 The following sample C code creates a thread to handle the receipt of a signal.
99 More specifically, it catches the asynchronously generated signal,
105 /********************************************************************
107 * compile with -D_POSIX_PTHREAD_SEMANTICS switch;
108 * required by sigwait()
110 * sigint thread handles delivery of signal. uses sigwait(\|) to wait
113 ********************************************************************/
122 static void *threadTwo(void *);
123 static void *threadThree(void *);
124 static void *sigint(void *);
135 sigfillset ( &signalSet );
137 * Block signals in initial thread. New threads will
138 * inherit this signal mask.
140 pthread_sigmask ( SIG_BLOCK, &signalSet, NULL );
142 printf("Creating threads\en");
144 pthread_create(&t, NULL, sigint, NULL);
145 pthread_create(&t2, NULL, threadTwo, NULL);
146 pthread_create(&t3, NULL, threadThree, NULL);
148 printf("##################\en");
149 printf("press CTRL-C to deliver SIGINT to sigint thread\en");
150 printf("##################\en");
157 printf("hello world, from threadTwo [tid: %d]\en",
159 printf("threadTwo [tid: %d] is now complete and exiting\en",
165 threadThree(void *arg)
167 printf("hello world, from threadThree [tid: %d]\en",
169 printf("threadThree [tid: %d] is now complete and exiting\en",
180 printf("thread sigint [tid: %d] awaiting SIGINT\en",
184 /* use standard-conforming sigwait() -- 2 args: signal set, signum
186 err = sigwait ( &signalSet, &sig );
188 /* test for SIGINT; could catch other signals */
189 if (err || sig != SIGINT)
192 printf("\enSIGINT signal %d caught by sigint thread [tid: %d]\en",
193 sig, pthread_self());
202 See \fBattributes\fR(5) for descriptions of the following attributes:
210 ATTRIBUTE TYPE ATTRIBUTE VALUE
212 Interface Stability Committed
214 MT-Level Async-Signal-Safe
216 Standard See \fBstandards\fR(5).
222 \fBsigaction\fR(2), \fBsigpending\fR(2), \fBsigprocmask\fR(2),
223 \fBsigsuspend\fR(2), \fBpthread_create\fR(3C), \fBpthread_kill\fR(3C),
224 \fBpthread_sigmask\fR(3C), \fBsignal.h\fR(3HEAD), \fBattributes\fR(5),
229 The \fBsigwait()\fR function cannot be used to wait for signals that cannot be
230 caught (see \fBsigaction\fR(2)). This restriction is silently imposed by the
234 Solaris 2.4 and earlier releases provided a \fBsigwait()\fR facility as
235 specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the
236 interface as described above. Support for the Draft 6 interface is provided for
237 compatibility only and may not be supported in future releases. New
238 applications and libraries should use the standard-conforming interface.