sigaction function has the same basic effect as
signal: to specify how a signal should be handled by the process.
sigaction offers more control, at the expense of more
complexity. In particular,
sigaction allows you to specify
additional flags to control when the signal is generated and how the
handler is invoked.
sigaction function is declared in signal.h.
Structures of type
struct sigactionare used in the
sigactionfunction to specify all the information about how to handle a particular signal. This structure contains at least the following members:
- This is used in the same way as the action argument to the
signalfunction. The value can be
SIG_IGN, or a function pointer. See Basic Signal Handling.
- This specifies a set of signals to be blocked while the handler runs. Blocking is explained in Blocking for Handler. Note that the signal that was delivered is automatically blocked by default before its handler is started; this is true regardless of the value in
sa_mask. If you want that signal not to be blocked within its handler, you must write code in the handler to unblock it.
- This specifies various flags which can affect the behavior of the signal. These are described in more detail in Flags for Sigaction.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The action argument is used to set up a new action for the signal signum, while the old-action argument is used to return information about the action previously associated with this symbol. (In other words, old-action has the same purpose as the
signalfunction's return value—you can check to see what the old action in effect for the signal was, and restore it later if you want.)
Either action or old-action can be a null pointer. If old-action is a null pointer, this simply suppresses the return of information about the old action. If action is a null pointer, the action associated with the signal signum is unchanged; this allows you to inquire about how a signal is being handled without changing that handling.
The return value from
sigactionis zero if it succeeds, and
-1on failure. The following
errnoerror conditions are defined for this function:
- The signum argument is not valid, or you are trying to trap or ignore