Interrupt processing is the key part of operating system and system software. Software interrupt under UNIX is called signal, which usually occurs in the following three situations
(1) When the user presses any key assigned to the signal control character by the terminal driver, the kernel sends a signal to the corresponding process. For example, we often input Ctrl + C to terminate the foreground process. At this time, the kernel sends the SIGINT signal to the process, and the default processing action of this signal is to terminate the process.
(2) When an error occurs in the execution of a process, the kernel will send the corresponding signal to the process. For example, illegal segment access, floating point overflow, or an illegal machine instruction. The kernel also uses signals to inform the process of specific events.
(3) A process can send a signal to another process through system call kill, so the signal can be used as a way of inter process communication.
When a process receives a SIGINT signal, it does not have to terminate. The process can tell the kernel how to process the signal through the signal function. There are three options for a process:
(1) Accept default processing (usually terminated)
The default processing mode is set for each signal in the system. The default processing of SIGINT is termination. The process does not have to accept the default processing mode, but the signal processing mode of the process can be restored to the default processing mode through the following calls:
(2) Ignore signal
Through the following call, the process can tell the kernel that it wants to ignore the SIGINT signal, so that it will not be terminated.
(3) Call the pre-defined signal processing function
This is the most powerful way.
The signal is generated by the kernel. In the following three cases, in this way, the kernel can be told which function should be called to process when the signal arrives. This function is called signal processing function. For example, a signal processing function, SIG, is installed for SIGINT signal_ fun（）：