In this quick tutorial, you will learn how to kill Linux processes using the kill command. The command can kill a single process or multiple processes, and there are varying levels of stopping a process, from graceful to very ungrateful.
It is always recommended to kill a process using the regular means, by stopping the service that created it, for example. Of course, there are circumstances where a service cannot be stopped to end a process, and sometimes something catastrophic happens and you are forced to “head-shot” the process, if you will.
Understanding the Kill Command
The kill command works by sending a signal to a process, and the signal instructs the process to halt itself. There are several signals available to be sent, with the default being quit or signal 3.
The various signals on Linux server are
|Signal||Signal Name (Description)|
|1||HUP (Hang up)|
|9||KILL (non-catchable, non-ignorable kill)|
|14||ALRM (Alarm clock)|
|15||TERM (software termination signal)|
The two most frequently used signals are 3 (Quit) and 9 (Kill).
Using the Kill Command
The kill command takes at least one argument, the process id (pid) of the process you want to end.
You may also specify multiple process IDs with the kill command, and kill will terminate them sequentially.
kill PID1 PID2 PID3
For example, to send a graceful quit command to an Apache2 process with a pid of 1200, you would use the following command.
To send a specific signal with the kill command, you use the – flag with the signal number.
kill -SIGNAL_NUMBER PID
Alternatively, you could use the -s flag and specify the signal name.
kill -s SIGNAL_NAME PID
For example, to kill the same Apache2 process with the kill signal, you would execute the following command.
kill -9 1200
Sending a kill signal of kill using the signal name.
kill -s KILL 1200