The representation of signals in the kernel
The actual execution signal processing action is called the Signal recursion (Delivery), the signal from produces to the recursion between the state, is called the Signal outstanding (Pending). A process can choose to block a signal. The blocked signal will remain in the pending state until the process has unblocked the signal before executing the recursive action. Note that blocking and ignoring are different, as long as the signal is blocked will not be reached, and ignore is the recursion after the optional processing action. The representation of a signal in the kernel can be seen as such:
Each signal has two flag bits representing blocking and pending, and a function pointer representing the processing action. When the signal is generated, the kernel sets the pending flag of the signal in the process control block until the signal is reached to clear the flag. In the example above,
1. The sighup signal is not blocked nor produced, and the default processing action is performed when it is reached.
2. SIGINT signal has been generated, but is being blocked, so for the moment can not reach. Although its processing action is ignored, the signal cannot be ignored until it is unblocked.
Because the process still has the opportunity to change the processing action before unblocking.
3. Sigquit signal has not been produced, once the generation of sigquit signal will be blocked, its processing action is the user-defined function Sighandler.
The pending and blocking flags can be stored with the same data type sigset_t. sigset_t is called a signal set, which can represent the "valid" or "invalid" state of each signal, and the meaning of "valid" and "invalid" in a blocking set is that the signal is blocked and "valid" in the pending signal set. and "Invalid" means whether the signal is in a pending state. The blocking signal set is also called the current process's signal screen word (Signal Mask), where the "mask" should be interpreted as blocking rather than ignored.
Second, signal set processing function
sigset_t type (64bit) for each signal with a bit for a "valid" or "invalid" state, as to how the internal storage of these bits is dependent on the system implementation, from the user's point of view is not concerned, the user can only call the following functions to manipulate sigset_t variables, There should be no explanation for its internal data, such as printing sigset_t variables directly with printf, which makes no sense.
#include <signal.h>
int Sigemptyset (sigset_t *set);
int Sigfillset (sigset_t *set);
int Sigaddset (sigset_t *set, int signo);
int Sigdelset (sigset_t *set, int signo);
int Sigismember (const sigset_t *set, int signo);
The function Sigemptyset initializes the set of signals that the set points to, so that the corresponding bit of all the signals is zeroed, indicating that the signal set does not contain any valid signals. The function Sigfillset initializes the set of signals that the set points to, so that the corresponding bit of all the signals is placed, indicating that the valid signal of the signal set includes all the signals supported by the system. Note that before using a variable of type sigset_t, it is important to invoke Sigemptyset or Sigfillset initialization to make the signal set in a determined state. After initializing the sigset_t variable, you can add or remove a valid signal in the signal set by calling Sigaddset and Sigdelset. These four functions are successfully returned 0, error return-1. Sigismember is a Boolean function that is used to determine whether a signal in a valid signal set contains a signal, if the inclusion returns 1, does not contain then returns 0, error returns-1.