Copyright (C) 2000-2012 |
GNU Info (libc.info)Advanced Signal HandlingAdvanced Signal Handling ------------------------ The `sigaction' function has the same basic effect as `signal': to specify how a signal should be handled by the process. However, `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. The `sigaction' function is declared in `signal.h'. - Data Type: struct sigaction Structures of type `struct sigaction' are used in the `sigaction' function to specify all the information about how to handle a particular signal. This structure contains at least the following members: `sighandler_t sa_handler' This is used in the same way as the ACTION argument to the `signal' function. The value can be `SIG_DFL', `SIG_IGN', or a function pointer. Note: Basic Signal Handling. `sigset_t sa_mask' This specifies a set of signals to be blocked while the handler runs. Blocking is explained in Note: 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. `int sa_flags' This specifies various flags which can affect the behavior of the signal. These are described in more detail in Note: Flags for Sigaction. - Function: int sigaction (int SIGNUM, const struct sigaction *restrict ACTION, struct sigaction *restrict OLD-ACTION) 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 `signal' function'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 `sigaction' is zero if it succeeds, and `-1' on failure. The following `errno' error conditions are defined for this function: `EINVAL' The SIGNUM argument is not valid, or you are trying to trap or ignore `SIGKILL' or `SIGSTOP'. automatically generated by info2www version 1.2.2.9 |