Differences between kill and pkill
First, let's talk about the kill command. It uses the pid to kill the process. To get the pid of a process, we can use the ps command. By default, the kill command sends a termination signal of 15 to the process, but some processes do not handle this signal. In this way, you can use the 9 signal to force the killing, signal 9 is a mandatory execution signal that will not be ignored.
Killall and pkill are both effective methods to terminate processes by using command names. They are different from kill killing processes by using pid. They can be understood as killing processes in batches, of course, the risk of doing so is also greatly increased. Of course, they can also send corresponding termination signals to processes.
For example, if we want to kill apache-related processes, we can use killall apache to kill all apache-related processes. This is convenient, but it may accidentally delete programs.
The following are the numbers and meanings of commonly used signals:
1 indicates the end signal sent from the terminal
2 indicates the terminal signal sent from the keyboard (that is, Ctrl + c)
3 indicates the exit signal sent from the keyboard (that is, Ctrl + \)
8 indicates a floating point exception, such as being divided by 0
9 indicates that the process receiving the signal is terminated, that is, the process is forcibly killed.
15 kill command default termination signal
17 signal of sub-process termination or termination
19 signal executed from the keyboard