Linux signal (signal): signal understanding

1. Understanding signal

1. What is the signal

  The signal in Linux is actually quite similar to the signal in daily life. The signal in LInux is an event notification mechanism, which notifies the process that a certain event has occurred. After the process receives the signal, it will interrupt the current operation, and then process the event represented by the signal.

  Each signal has its own corresponding event, there are many kinds of signals, and there are also many kinds of events. To process events, a process naturally needs a corresponding processing method. Each signal has its own corresponding processing method, which is actually a signal processing function. After the process receives the signal, it executes the processing function corresponding to the signal.

  Use an example in life to understand the signal: take crossing the road as an example, crossing the road is a process, when you walk to the side of the road and see the signal light is red (the red signal light is the signal), this signal tells us that we cannot cross now, we have to wait for a while (The processing function of the red signal is to stop and wait for the green light). Therefore, our process of crossing the road is interrupted. The processing function of this signal is to wait for the arrival of the green light. After the execution of the function corresponding to this signal is completed, we can continue to cross the road.

  Signals are actually macros , as shown in the following figure:

insert image description here

2. Types of signals

 Command to view signals:

  • kill -l

  As shown in the figure: There are 64 kinds of signals in Linux, 1 ~ 31 are unreliable signals (non-real-time signals), and 32 ~ 64 are reliable signals (real-time signals).

Signal type

The difference between real-time signal and non-real-time signal:

  1. The real-time signal has a high priority, and the system processes the real-time signal first.
  2. Live signals record the number of times the signal is sent, while non-real time signals do not. (This is very important)

2. Simple understanding of the life cycle of signals

  The life cycle of a signal is divided into four parts:

  • Generate: like a red light is on, this generates a signal
  • Registration: It is to let the process know that it has received a certain signal. It's like when we see a red light, we know we have a red light signal.
  • Logout: The process erases the existence of the signal before processing the signal.
  • Processing: call the processing function of the signal

Guess you like

Origin blog.csdn.net/weixin_57761086/article/details/128780661