Sometimes, in your system some applications becomes unresponsive and unexpectedly crashes. Even after starting again it will not work because of the application process not shuts down completely. In such situation, you need to stop or terminate the process or kill the application process. In Linux, you can kill the process using multiple ways. This article shows you how to use kill
commands to terminate a process in Linux.
System Kill Signals
When you use kill
, killall
, and pkill
command, it sends a given signal to specified processes or process groups. When no signal is specified, each tool sends 15
(TERM
).
Below are most used signals:
1 (-HUP)
: to reload a process.9 (-KILL)
: to kill a process.15 (-TERM)
: to gracefully stop a process.
You can specify the signals by three different ways:
- using a number (e.g., -1)
- with the “SIG” prefix (e.g., -SIGHUP)
- without the “SIG” prefix (e.g., -HUP).
To list the all available signals use -l
option with kill
command:
kill -l # or killall -l
Terminate Process Using kill Command
To use the kill command, first you need the process PID. You can find PID using the top
, ps, pidof
or pgrep
command.
For example, if your Google Chrome browser is unresponsive and you want to kill the process. You should first find the PID of Google Chrome using the pidof command:
pidof google-chrome
It show all the all Chrome processes:
3551 2010 1920 1845
Once you know the Firefox processes PIDs to terminate all of them send the TERM
signal:
kill -9 3551 2010 1920 1845
Terminate Process Using killall Command
The killall
command is useful when you want to kill
all the processes of specified program.
For previous example, you can kill
the Chrome processes by below command:
killall -9 google-chrome
You also can pass the several option along with killall command, like sending signals to processes owned by a given user, matching processes names against regular expressions, and the creation time. To get the list of all options of the killall command, run the killall command without any option.
For instance, if you want to terminate all processes running for a user tecnstuff
, you just need to type as following:
sudo killall -u tecnstuff
Terminating Processes Using pkill Command
The pkill
command terminates processes that match the pattern given on the command line:
pkill -9 google-chrome
The name of the process doesn’t have to be an exact match.
You also can send the signal with pkill command to the processes of a specified user. To kill only the chrome processes owned by the user tecnstuff
, you would type:
pkill -9 -u tecnstuff google-chrome
Conclusion
When some application becomes unresponsive you can terminate using the kill, killall and pkill commands. You just need to find the PID or process name.
If you have any question or feedback, please leave a comment below.