Signal Mask – Blocked signal set
Each process has a set of signals that describe which signal is transmitted to be blocked, and if a signal is in a blocking signal set in a process, the signal transmitted to that process will be blocked. The signal set currently blocked by the process is also called a signal mask, and the type is sigset_t. Each process has its own signal mask, and when a child process is created, the child process inherits the parent process's signal mask.
The difference between signal blocking and ignoring
The concept of blocking is different from ignoring the signal: the operating system will not pass the signal until the signal is unblocked by the process, the blocked signal will not affect the behavior of the process, the signal is only temporarily blocked from passing; When a process ignores a signal, the signal is passed out, but the process discards the signal.
Operation of the signal set
int Sigemptyset (sigset_t *set); Clear Signal Set
int Sigfillset (sigset_t *set); Fills all signals into the signal set set
int Sigaddset (sigset_t *set, int signum); Adding a signal to the set of signals Signum
int Sigdelset (sigset_t *set, int signum); Move the signal out of the signal set set Signum
The above four functions return: 0 If successful, or 1 if there is an error
int Sigismember (const sigset_t *set, int signum); Determines whether Signum is contained in the set, returns 1, and does not return 0.
int sigprocmask (int how, const sigset_t *set, sigset_t *oldset); Set the processing mode of the signal in the signal shielding set (blocking or not blocking)
Parameter description:
How: Used to specify the way the signal is modified, there may be a choice of 3
Sig_block adds the signal contained in the set of signals to the current signal mask. That is, the signal mask and set signal set are performed or manipulated.
Sig_unblock removes the signal contained in the signal set pointed to by the set from the current signal mask. That is, the signal mask and set are manipulated.
Sig_setmask sets the value of the set to the new process signal mask. That is, set assigns a signal mask to a value operation.
Set: As a pointer to the signal set, this refers to the new set of signals, if you want to read only the current mask value, you can set it to null.
Oldset: Also a pointer to the signal set, where the original signal set is stored. can be used to detect what signal is present in the signal mask.
Return value: 0 is returned when executed successfully. The failed return -1,errno is set to Einval.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux Signal set operation