The
Kill command does exactly what it sounds like: it kills a process. It sends a signal to a process to kill itself. Here are three ways to kill a linux process:
Step one: find the process
Suppose you wanted to kill a certain httpd process. First, you need to find it:
# ps -ef | grep firefox
2073 ? Sl 1:07 /usr/lib/firefox-3.5.3/firefox
There are other ways to effectively kill a process — killing a process by name, killing a process by specifying part of the name, killing a process by pointing out the process with cursor etc.,
In this article, let us review 4 ways to kill a process.
1. Kill Command – Kill the process by specifying its PID
All the below kill conventions will send the TERM signal to the specified process. For the signals, either the signal name or signal number can be used. You need to lookup the pid for the process and give it as an argument to kill.
$ kill -TERM pid
$ kill -SIGTERM pid
$ kill -15 pid
Example: Kill the firefox process.
$ ps -ef | grep firefox
2073 ? Sl 1:07 /usr/lib/firefox-3.5.3/firefox
$ kill -9 1986
2. Killall Command – Kill processes by name
Instead of specifying a process by its PID, you can specify the name of the process. If more than one process runs with that name, all of them will be killed.
Example: Kill all the firefox processes
$ killall -9 firefox
3. Pkill Command – Send signal to the process based on its name
You can send signal to any process by specifying the full name or partial name. So there is no need for you to find out the PID of the process to send the signal.
Example: Send SIGTERM to all the process which has sample in its name.
$ pkill sample