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
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.