In the previous section, one of the ways of interprocess communication is the signal generation and capture function in signal communication, this section introduces the signal () function and the SET function group of signal processing functions, and then a section http://blog.csdn.net/mybelief321/article/details/9078193
It is highly recommended to do a final experiment!
Signal Processing method
The signal processing method mainly has the following two kinds:
① uses the signal () function;
② uses a set of signal set functions.
Using the signal () function
Function description
When you use the signal () function, you simply point to the signal and the processing function that you want to work with. It is mainly used in the first 32 kinds of non real-time signal processing, and does not support signal transmission information. Linux also supports a more robust update of the signal processing function, which is sigaction (), and is recommended for use in this function.
function format
Here signal () the prototype of this function I looked at the head a bit large, or to explain first: first of all, the function prototype points to a function pointer without a return value and with an integer parameter, which is the original configuration function of the signal, and then the prototype has two parameters, of which the 2nd A parameter can be a function pointer to a user-defined signal processing function. Do not understand also nothing, behind the experiment will understand, will be used on the line.
Here is a description of the sigaction structure used for the 2nd and 3rd parameters in the Sigaction () function, and the following table defines the siaction:
Sa_handler is a function pointer that specifies the signal processing function, which can be used in addition to our custom processing functions, either for SIG_DFL (with default processing) or for sig_ign (ignoring the signal). Its handler function has only one parameter, namely the signal value.
Sa_mask is a set of signals that specifies which signals should be masked during the execution of a signal handler, and that the signal set is added to the signal mask word before the signal capture function is invoked.
The sa_flags contains a number of flag bits, which are the various options for processing the signal. Its common optional values are shown in the following table: