System Calls sigwait(2)
NAME
sigwait - wait until a signal is posted
SYNOPSIS
#include
int sigwait(sigsett *set);
Standard conforming
cc [ flag ... ] file ... -DPOSIXPTHREADSEMANTICS [ library...]
#include
int sigwait(const sigsett *set, int *sig);
DESCRIPTION
The sigwait() function selects a signal in set that is pend-
ing on the calling thread (see thrcreate(3C) and
pthreadcreate(3C).) If no signal in set is pending,
sigwait() blocks until a signal in set becomes pending. The
selected signal is cleared from the set of signals pending
on the calling thread and the number of the signal is
returned, or in the standard-conforming version (see stan-
dards(5)) placed in sig. The selection of a signal in set is
independent of the signal mask of the calling thread. This
means a thread can synchronously wait for signals that are
being blocked by the signal mask of the calling thread . To
ensure that only the caller receives the signals defined in
set, all threads should have signals in set masked including
the calling thread. If the set argument points to an invalid
address, the behavior is undefined and errno may be set to
EFAULT.
If sigwait() is called on an ignored signal, then the
occurrence of the signal will be ignored, unless sigaction()
changes the disposition. If more than one thread waits for
the same signal, only one is unblocked when the signal
arrives.
RETURN VALUES
Upon successful completion, the default version of sigwait()
returns a signal number; the standard-conforming version
returns 0 and stores the received signal number at the loca-
tion pointed to by sig. Otherwise, -1 is returned and errno
is set to indicate an error.
ERORS
The sigwait() function will fail if:
SunOS 5.11 Last change: 24 Jun 2002 1
System Calls sigwait(2)
EINTR The wait was interrupted by an unblocked, caught
signal.
EINVAL The set argument contains an unsupported signal
number.
The sigwait() function may fail if:
EFAULT The set argument points to an invalid address.
EXAMPLES
Example 1 Creating a thread to handle receipt of a signal
The following sample C code creates a thread to handle the
receipt of a signal. More specifically, it catches the asyn-
chronously generated signal, SIGINT.
/********************************************************************
*
* compile with -DPOSIXPTHREADSEMANTICS switch;
* required by sigwait()
*
* sigint thread handles delivery of signal. uses sigwait() to wait
* for SIGINT signal.
*
********************************************************************/
#include
#include
#include
#include
#include
#include
#include
static void *threadTwo(void *);
static void *threadThree(void *);
static void *sigint(void *);
sigsett signalSet;
void *
main(void)
{
pthreadt t;
pthreadt t2;
pthreadt t3;
SunOS 5.11 Last change: 24 Jun 2002 2
System Calls sigwait(2)
sigfillset ( &signalSet );
/*
* Block signals in initial thread. New threads will
* inherit this signal mask.
*/
pthreadsigmask ( SIGBLOCK, &signalSet, NUL );
printf("Creating threads\n");
pthreadcreate(&t, NUL, sigint, NUL);
pthreadcreate(&t2, NUL, threadTwo, NUL);
pthreadcreate(&t3, NUL, threadThree, NUL);
printf("##################\n");
printf("press CTRL-C to deliver SIGINT to sigint thread\n");
printf("##################\n");
pthreadexit((void *)0);
}
static void *
threadTwo(void *arg)
{
printf("hello world, from threadTwo [tid: %d]\n",
pthreadself());
printf("threadTwo [tid: %d] is now complete and exiting\n",
pthreadself());
pthreadexit((void *)0);
}
static void *
threadThree(void *arg)
{
printf("hello world, from threadThree [tid: %d]\n",
pthreadself());
printf("threadThree [tid: %d] is now complete and exiting\n",
pthreadself());
pthreadexit((void *)0);
}
void *
sigint(void *arg)
{
int sig;
int err;
printf("thread sigint [tid: %d] awaiting SIGINT\n",
pthreadself());
/*
/* use standard-conforming sigwait() -- 2 args: signal set, signum
*/
SunOS 5.11 Last change: 24 Jun 2002 3
System Calls sigwait(2)
err = sigwait ( &signalSet, &sig );
/* test for SIGINT; could catch other signals */
if (err sig != SIGINT)
abort();
printf("\nSIGINT signal %d caught by sigint thread [tid: %d]\n",
sig, pthreadself());
pthreadexit((void *)0);
}
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
Interface Stability Standard
MT-Level Async-Signal-Safe
SEE ALSO
sigaction(2), signal.h(3HEAD), sigpending(2), sigproc-
mask(2), sigsuspend(2), pthreadcreate(3C),
pthreadsigmask(3C), thrcreate(3C), thrsigsetmask(3C),
attributes(5), standards(5)
NOTES
The sigwait() function cannot be used to wait for signals
that cannot be caught (see sigaction(2)). This restriction
is silently imposed by the system.
Solaris 2.4 and earlier releases provided a sigwait() facil-
ity as specified in POSIX.1c Draft 6. The final POSIX.1c
standard changed the interface as described above. Support
for the Draft 6 interface is provided for compatibility only
and may not be supported in future releases. New applica-
tions and libraries should use the standard-conforming
interface.
SunOS 5.11 Last change: 24 Jun 2002 4
|