Linux signal (on) - signal concept / signal processing / etc.

It only takes 6 minutes to read the whole article


  • The concept of signals in life can be imagined (traffic lights), so what is the concept of signals in Linux?

In fact, it is easy to understand. First of all, there are many kinds of signals, and different signal processing methods are also different (three processing methods, default, ignore <>, capture < require the kernel to switch to user mode to execute this processing function when processing the signal, this kind of The method is called catching (Catch) a signal>);
before receiving the signal, it has been instructed how to deal with it. (The above two are also the characteristics of the signal)

  • Who is the signal sent to? How to send?

There are many senders of signals, such as terminal drivers, processes, and systems. And the receiver is mostly a process.

So how to do it is to send a signal to a process? In fact, sending a signal to a process is to modify the signal field in the pcb structure of the target process (let the process record the signal). Think about it, what data structure can be used to solve this problem?

The answer is also simple, whether a process receives a signal is itself an atomic question. It either got it or it didn't. So you can use a bitmap to indicate whether a process has received a signal.

  • Notice:

    1. Ctrl + C generates a signal, which can only be sent to the foreground process;

    2. Adding & after a command can be placed in the background to run, so that the shell can accept new commands and start new programs without waiting for the process to end;

    3. A shell You can run one foreground process and any number of background processes, only the foreground process can receive the signal generated by the control key Ctrl + C;

    4. The foreground process will generate a signal at any time by pressing Ctrl + C during the running process, so The process will be terminated by receiving the SIGINT signal, so the signal is asynchronous relative to the process control flow.


  • Knowing the concept of signals, it is also easy to view the list of signals defined in the system:

kill -l command

write picture description here

At first glance, it looks like there are 64 signals, but if you look closely, you'll see that's not the case. No signals 32 and 33. There are only 62 signals in total. . .

Numbers 1-33 are called ordinary signals, and numbers 34-64 are real-time signals, where each signal has a number and a macro definition name, which can be found in the header file signal.h.

  • Under what conditions are these signals generated? What are the default processing actions? They are all explained in detail in signal(7), and you can view them by typing man 7 signa on the command line:

write picture description here


  • next notice

  • All the basic concepts are known, so how is the signal generated?

Terminal key generation

Hardware exception generates signal

system call generation

software conditional generation

  • There are several issues here that are worth noting:
    1. What happened to dereferencing a null pointer?
    2. What is the difference between library functions and system calls?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325847853&siteId=291194637