[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
Signal processing is LinuxProgram. It is the best choice for our system programmers to use signal processing to simulate the interrupt function of the operating system. To use the signal processing function, you must enter a signal processing function. Once the process processes the signals to be processed, the process will immediately process them.
# Include <stdio. h> # include <stdlib. h> # include <signal. h> int value = 0; void func (INT sig) {printf ("I get a signal! \ N "); value = 1;} int main () {signal (SIGINT, func); While (0 = value) sleep (1); Return 0 ;}
To display the signal processing process in Linux, two steps are required. First, enter GCC Sig. c-O sig, and then input. /Sig. Second, restart a console window, enter PS-Aux | grep Sig, and then enter kill-int 2082 after obtaining the PID of SIG. Then we can get the following output.
[Root @ localhost fork] #./Sigi get a signal! [Root @ localhost fork] #