The difference between kill -15 and kill -9

kill -15 and kill -9 are commonly used commands, both of which can be used to kill processes.

So what is the difference between kill -15 and kill -9?

kill - followed by a signal, such as 9, 15

Communication between processes is to allow two processes to interact with each other. Communication between pipe character processes. Another type is the signal ctrl +c, which also means the same as signal and kill.

Kill introduction: If a process needs to be stopped halfway through execution, or a large amount of system resources have been consumed, you can consider stopping the process at this time. Use the kill command to accomplish this task.

kill -15

The default signal of the kill command is 15, which is kill -15, which is called a graceful exit.

When using kill -15, the system will send a SIGTERM signal to the corresponding program. When the program receives the signal, it can decide how to handle it.

At this point, the application can choose to:

1. Stop the program immediately

2. Stop the program after releasing the response resources

3. Ignore the signal and continue executing the program

Because the kill -15 signal only notifies the corresponding process to perform a "safe and clean exit", after the program receives the signal, it will generally perform some "preparatory work" before exiting, such as resource release, temporary file cleaning, etc. , if the preparation work is completed, the program will be terminated. However, if there is a blocking or other problem that prevents success during the "preparation" process, the application can choose to ignore the termination signal.

This is why we sometimes cannot "kill" an application using the kill command, because the default kill signal is SIGTERM (15), and the SIGTERM (15) signal can be blocked and ignored.

After receiving the SIGTERM signal, most programs will first release their own resources and then stop.

But there are also programs that can do other things after receiving the semaphore, and these things can be configured.

If the program is waiting for IO, it may not respond immediately, or it may wait for responses from other projects.

clil -9

The core process will ignore the kill command, but kill -9 will tell the kernel that I want to force kill.

kill -9 is to forcefully kill a process, no matter how important the process is.

In layman's terms, it can be understood that an adult cat has 9 lives, and it has to kill them all.

The difference between kill -15 and kill -9

Compared with kill -15, kill -9 is relatively tough. The system will send out the SIGKILL signal. It requires that the program that receives the signal should end its operation immediately and cannot be blocked or ignored.

Therefore, compared with the kill -15 command, when kill -9 is executed, the application does not have time to perform "preparation work", so this usually brings some side effects, such as data loss or the terminal cannot be restored to normal state, etc. .

If you reprint, please indicate the source: Open Source Byte  https://sourcebyte.vip/article/336.html

Guess you like

Origin blog.csdn.net/qq_35634154/article/details/132815603