Standards
Standards / Extensions |
C or C++ |
Dependencies |
XPG4.2
Single UNIX Specification, Version 3
|
both |
POSIX(ON)
|
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <signal.h>
void (*sigset(int sig, void (*disp)(int)))(int);
General description
The sigset()
function provides a simplified method for changing the action associated
with a specific signal and unblock the signal, or to block this signal.
- sig
- The number of a recognized signal. sigset() sets the action associated
with this signal and unblock this signal, or adds this signal to the
calling thread's signal mask (thus blocking this signal). Refer to Table 1 for a list of the supported
values of sig.
The value of sig can
be any valid signal type except SIGKILL, SIGSTOP, or SIGTRACE.
- disp
- There are four possible value that disp can
have. Three are actions that can be associated with the signal, sig:
SIG_DFL, SIG_IGN, or a pointer to a function. The fourth value is
not a signal action, but a flag to sigset() that affects whether the
signal action is changed.
The values that
disp is
permitted to have are:
- SIG_DFL
- Set the signal action
to the signal-specific default.
- The default actions for each signal is shown in Table 1.
- If disp is set to SIG_DFL, sigset()
will change the signal action associated with sig and
remove this signal from the calling thread's signal mask (thus unblocking
this signal).
- If the default action is to stop the process, the execution of
that process is temporarily suspended. When a process stops, a SIGCHLD
signal will be generated for its parent process, unless the parent
process has set the SA_NOCLDSTOP flag. While a process is stopped,
any additional signals that are sent to the process will not be delivered
until the process is continued, except SIGKILL which always terminates
the receiving process. A process that is a member of an orphaned
process group will not be allowed to stop in response to the SIGTSTP,
SIGTTIN, or SIGTTOU signals. In cases where delivery of one of these
signals would stop such a process, the signal will be discarded.
- Setting a signal action to SIG_DFL for a signal that is pending,
and whose default action is to ignore the signal (for example SIGCHLD),
will cause the pending signal to be discarded.
- SIG_IGN
- Set the signal action
to ignore the signal.
- Delivery of the signal will have no effect on the process.
- If disp is set to SIG_IGN, sigset()
will change the signal action associated with sig and
remove this signal from the calling thread's signal mask (thus unblocking
this signal).
- Setting a signal action to SIG_IGN for a signal that is pending
will cause the pending signal to be discarded. This provides the ability
to discard signals that are found to be blocked and pending by sigpending().
- If sig is SIGCHLD, child processes of
the calling process will not be transformed into 'zombie' processes
when they terminate. If the calling process subsequently waits for
its children, and the process has no unwaited from children that were
transformed into 'zombie' processes, it will block until all of its
children terminate. The wait(), waitid(), or waitpid() function will
fail and set errno to ECHILD.
- SIG_HOLD
- Set the calling thread's signal
mask to block signal, sig.
- The signal action associated with sig is
not changed.
- Pointer to function
- Set the signal action to catch the signal.
After an action has been specified for a particular
signal, using sigset(), it remains installed until it is explicitly
changed with another call to sigset(), sigaction(), signal(), one
of the exec functions, bsd_signal(), or sigignore().
Special
behavior for C++: - The behavior when mixing signal-handling with C++ exception
handling is undefined. Also, the use of signal-handling with constructors
and destructors is undefined.
- C++ and
C language linkage conventions are incompatible, and therefore sigaction()
cannot receive C++ function
pointers. If you attempt to pass a C++ function
pointer to sigaction(), the compiler will flag it as an error. Therefore,
to use the sigaction() function in the C++ language,
you must ensure that signal handler routines established have C linkage,
by declaring them as extern "C".
Usage notes
The use of the SIGTHSTOP and SIGTHCONT signal
is not supported with this function.
Returned value
If successful, sigset()
returns SIG_HOLD if the signal had been blocked and the signal's previous
action if it had not been blocked.
If unsuccessful, sigset()
returns SIG_ERR and sets errno to one of the following values:
- Error Code
- Description
- EINVAL
- The value of the argument sig was not
a valid signal type, or it was SIGKILL, SIGSTOP, or SIGTRACE.