Signal and Signal processing
Introduction of 1.Linux Signal
The signal is a software interrupt. A signaling mechanism that is extended in Linux systems based on POSIX standards.
1. Signal source
1. Hardware mode
1. When the user presses a key, a signal is generated, such as Crtl+c
2. Hardware exception generated signal, divisor is 0, invalid storage access, etc.
2. Software method
1. The user invokes the KILL command to send arbitrary signals to the process
2. Process call kill or Sigqueue function send signal
3. Detection of a software condition already has a signaling condition, such as a timer set by the alarm
2. Type of signal
Linux command kill-l lists all the supported signals
[Email protected] c]$ kill-l
1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP
6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL) SIGUSR1
One) (SIGSEGV) (SIGUSR2) sigpipe) sigalrm) SIGTERM
Sigstkflt) (SIGCHLD) Sigcont SIGSTOP) SIGTSTP
(Sigttin) Sigttou () Sigurg) sigxcpu) Sigxfsz
(SIGVTALRM) sigprof) sigwinch SIGIO) SIGPWR
Sigsys) (sigrtmin) sigrtmin+1) sigrtmin+2 Notoginseng) sigrtmin+3
sigrtmin+4) sigrtmin+5 (sigrtmin+6) sigrtmin+7) sigrtmin+8
sigrtmin+9) (sigrtmin+10) sigrtmin+11 () sigrtmin+12) sigrtmin+13
(sigrtmin+14) sigrtmin+15 () SIGRTMAX-14) SIGRTMAX-13) SIGRTMAX-12
SIGRTMAX-11) SIGRTMAX-10 SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7
(SIGRTMAX-6) (SIGRTMAX-5) SIGRTMAX-4) SIGRTMAX-3) SIGRTMAX-2
SIGRTMAX-1) Sigrtmax
The value of the signal is defined in signal.h.
1. Reliable signal and unreliable signal
SIGHUP (No. 1th)----Sigsys (31st) inherited from UNIX, is unreliable signal
Liunx defined according to the POSIX standard: sigrtmin (33rd)------Sigrtmax (64th) reliable signal, also called real-time signal
Linux has no signal numbers 16th and 32nd.
The reliability of a signal is whether the signal is lost, or whether the signal supports queuing.
Signal generation and delivery have a time interval, called signal pending.
Signal will be delivered multiple times, reliable signal
Delivery only once, unreliable signal
2. Signal Priority
Smaller numbers are delivered first, unreliable signals are delivered first
3. Process response to the signal
1. Capturing signals
2. Ignore the signal
3. By system default: The usual default action is to terminate the process
2. Signal Processing
1. Capture and processing of signals
2. Return of signal processing functions
3. Sending of Signals
4. Shielding of the signal
Linux C program signal and Signal processing (19)