We already know that we can terminate the process through the signal, but also through the signal to the process of communication, the program can also specify the signal by the association handler function to change the signal default processing mode, can also block some signals, so that it cannot be passed to the process. So how do we set the signal we need to deal with and what signals we don't have to deal with? Signal set function is to help us solve these problems.
For more information about using signal communication between Linux processes, see my other article--linux interprocess communication--using a signal
The following is a set of signal functions:
1, int sigemptyset (sigset_t *set);
The function is to initialize the signal set to NULL.
2, int sigfillset (sigset_t *set);
The function is to initialize the signal set to include all the defined signals.
3, int sigaddset (sigset_t *set, int signo);
The function is to add the signal Signo to the set of signal sets, return 0 when successful, and return 1 when failed.
4, int sigdelset (sigset_t *set, int signo);
The function is to remove the signal signo from the set of signal sets, return 0 when successful, and return 1 when failed.
5, int sigismember (sigset_t *set, int signo);
The function is to determine whether a given signal signo is a member of a signal set, if it returns 1, if not, return 0 if the given signal is invalid, return-1;
6, int sigpromask (int how, const sigset_t *set, sigset_t *oset);
The function can modify the signal mask word of a process based on the method specified by the parameter. The new signal screen Word is specified by the parameter set (Non-empty), and the original signal mask word is stored in Oset (non-empty). If the set is empty, how does not make sense, but call the function at this time, and if the oset is not empty, save the current signal mask Word to the oset.
How the different values and operations are as follows:
If the Sigpromask completes successfully returns 0, if the How value is invalid returns-1, and sets errno to Einval.
Note: This function can be called to change the process of the screen word, the previous function is to change the value of a variable, does not really affect the process of the screen word.
7, int sigpending (sigset_t *set);
The function is to write a set of signals stuck in the pending state in the blocked signal to the set of signals that the parameter set points to, the successful call returns 0, otherwise return 1, and set errno to indicate the cause of the error.
8, int sigsuspend (const sigset_t *sigmask);
This function suspends the execution of the process by replacing the process's masked word with a set of signals given by the parameter sigmask. Note that the order of action is to replace and suspend the execution of the program first. The program will continue execution after the signal processing function has finished executing. If a signal is received that terminates the program, Sigsuspend does not return, and if the received signal does not terminate the program, Sigsuspend returns-1 and sets the errno to Eintr.
Special reminder: If a signal is blocked by a process, it is not passed to the process, but it stays in the pending state, and when the process is disposed of blocking the processing signal, the pending signal will be processed immediately.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/