The difference between kill and kill -9
kill command format:
kill -Signal pid
pid
is the process number, which can be found out with the ps
command
signal
is a signal sent to the process
kill
and kill -9
, both commands have the effect of killing the process in Linux. However, the execution process of the two commands is quite different. If used incorrectly in the program, it may It will cause inexplicable phenomena.
kill(不加 -* 默认kill -15)
Order
The system will send aSIGTERM
signal to the corresponding program. When the program receives the signal, the following things will happen:
- The program stops immediately
- Stop when the program releases the corresponding resources
- The program may still continue to run
After receiving the signalSIGTERM
, most programs will first release their own resources and then stop. However, some programs may do other things after receiving the signal (if the program is waiting for IO, it may not respond immediately), that is to say, SIGTERM
may be blocked. .
kill -9
Order
The signal sent by the system to the corresponding program is SIGKILL
, that is, exit
. exit
The signal will not be blocked by the system, so kill -9
can kill the process smoothly.
瀻结:
- Before using kill -9, you should first use kill -15 to give the target process a chance to clean up the aftermath. If not, some incomplete files or status may be left, preventing the service from starting again.