How to Kill a Process in Linux
The command that is used to kill a process in Linux is the kill command. kill is one of the commands that does not have too many options. The following most-common options are available for kill:
n: n is an integer and denotes the process identifier (PID) of the process. The signal is sent only to the process with the PID.
-n: n is an integer and denotes the process group. The signal is sent to all of the processes in this process group.
-s: The signal to be sent to the process. s can be a signal name or number.
-l: Print a list of signal names.
To kill the process in Linux, we have to know the process ID of the process that we want to kill. We can get the PID of the application by the ps command together with the grep command, such as ps aux | grep firefox. This command will display various information about the Firefox process, including its PID; assume that it is 1572. To kill the Firefox process, we will use the kill command as:
if we want to force the process to be killed immediately, we will use
kill –SIGTERM 1572
kill -9 1572
We could also use killall command to end all the process tree of Firefox. In that case, the command would be:
As you have just caught, killall takes process name as the argument, not the PID.
Do not use the killall command in UNIX! The usage and syntax is different.
The kill command comes especially handy if your system is responding slowly due to an application. Also, you can use the command to kill the entire desktop manager if your desktop becomes totally unresponsive. In this case, switch to another virtual session (hit Ctrl + Alt + F1), log on to the system and issue the killall gdm or killall kdm to end the Gnome or KDE desktop session.