Linux 101: kill and killall
If you've come across an application or a process that just won't die, and you're thinking that you might want to reboot your machine - STOP! There is no need for rebooting in Linux (unless you've just upgraded your kernel). There are plenty of ways to get rid of an application that refuses to listen to the File Â > Exit or File > Quit or that handy X button in the upper right corner. When you've exhausted all of your options, there is always the command line.
For taking care of stubborn Linux applications, there are two very helpful commands: kill and killall. But how are they used? Are the complicated or are they simple? Let's examine these two very handy commands.
Oh no. These two commands are installed in all Linux distributions by default. To use them all you have to do is open up a terminal window and start blowing away applications. But which should you use?
The man page of the kill command states that kill will "send a signal to a process." That sounds harmless enough. But what is the signal it sends? If reason stands, that signal would be one to terminate the process. Oddly enough TERM (short for terminate) is not the only signal kill can send. There is a fairly lengthy list of possible signals (all of them different) that can be had by issuing the command kill -l. You will find 62 different signals you can send with kill. The default is TERM which will terminate a process.
So, how do you use kill? Simple. You first must know the process ID of the process you want to kill. Let's say good ol' Firefox isn't responding and you need to get rid of it. To do this you first need to find out what the PID of the currently running Firefox is. To do this you would issue a command like:
ps aux|grep firefox
Which would return something like:
jlwallen 18387 Â 0.0 Â 0.0 Â 1832 Â 556 ? Â Â Â Â S Â Â 16:53 Â 0:00 /bin/sh /usr/lib/firefox-3.6.12/firefox
jlwallen 18392 Â 0.0 Â 0.0 Â 1832 Â 572 ? Â Â Â Â S Â Â 16:53 Â 0:00 /bin/sh /usr/lib/firefox-3.6.12/run-mozilla.sh /usr/lib/firefox-3.6.12/firefox-bin
jlwallen 18396 26.0 Â 2.2 201420 46492 ? Â Â Â Â Dl Â 16:53 Â 0:01 /usr/lib/firefox-3.6.12/firefox-bin
jlwallen 18413 Â 0.0 Â 0.0 Â 3324 Â 816 pts/0 Â Â S+ Â 16:53 Â 0:00 grep --color=auto firefox
The PID you are looking for will be the one associated with firefox-bin. In the example above, that PID is 18396. So to kill Firefox you would then issue the command kill 18396. That command would instantly kill Firefox.
There is an easier way!
What if you don't want to jump through the hoops of finding the PID of the process. If you know the name of the process you can, instead, make use of the killall command. Instead of killing a process by ID, killall kills a process by name. There are signals you can send with killall (either by name or number), but the one that is most often used is -9. So to kill Firefox with killall you would issue the command:
killall -9 firefox-bin
The obvious problem with this is you must know the exact name of the process you want to kill. So if you don't know the name you can go back ps aux|grep firefox to get the exact name of the process.Advertisement