One of the things I hate about Windows is that there is no good way to kill frozen processes. Theoretically, you type Ctrl-Alt-Delete, wait for Task Manager to pop up, and kill the process. But in reality, the process doesn't always die immediately (it usually takes multiple tries and a very long time). GNU/Linux users don't have this problem. Here's how to end processes using the terminal, a few GUIs, and even a first person shooter.
Killing processes in the terminal
The terminal (also known as the command line) is the most powerful tool for virtually any job. So let's look at how to kill processes with it. First, open your favorite terminal program (konsole for KDE, gnome-terminal for Gnome, and xterm are some good ones). Then, type ps -A (not ps -a). This gives you a listing of all the programs currently running and their PID. To kill a program, type kill PIDHERE, replacing PIDHERE with the PID of the program as shown by ps. See figure 1 for an example. Note that sometimes you will get error messages when trying to kill a program. If you do, you must kill the program as root (sudo kill PIDHERE or su and then kill PIDHERE depending on the operating system).
Often, the searching through ps's output is like searching for a semi-colon in a 5MB source file. Luckily, if you know the name of the program, it's easy to find it. Instead of typing ps -a, type ps -A | grep NAMEHERE, replacing NAMEHERE with the string you want to find. For example, if I typed ps -A | grep fire, all the processes with the string fire in them would be listed. You can also add the -i flag to grep (so you'd type ps -A | grep -i fire) to make the search string case insensitive.
Killing processes with GUIs
Both KDE and Gnome provide their users with GUIs for killing processes. In KDE, run KSysGuard (many distributions also use Ctrl-Esc). Just click on the tab, "ProcessTable", select the item, and click "Kill". In Gnome, open System Monitor (aka Gnome System Monitor), select the "Processes" tab, select the item, and hit "End Process". If you can't kill the process, try running the KSysGuard or Gnome System Monitor as root (see previous paragraph for more).
If you just want to kill an inactive window without having to dig up a PID or running a bloated GUI, there's an option called xkill. Just open a terminal, and type xkill. Click on a window, and it will be killed (right-click to cancel). KDE users can also type Ctrl-Alt-Esc to bring up xkill.
A bonus: killing processes and having fun
If you really want to "kill" a process, then you need to try psDooM (figure 2). Download (make sure it isn't a patch, but a source or a binary) and install it, copy an IWAD (Freedoom has a few available) into wherever you installed psDooM (usually /usr/local/games/psdoom), and then run one of the executables located in the folder. Now, when you get mad at the world, all you have to do is open up a Microsoft product in WINE, and then shoot it.
Conclusion
You now know how to kill a process with the terminal, kill a process with KSysGuard, Gnome System Monitor, or xkill, and even shoot a process! Next time a Microsoft user complains about his system freezing, all you have to do is grin and show him GNU/Linux.


Comments
pgrep & pkill
may i recommend pgrep and pkill over ps, grep, and kill.
by example:
$ pgrep init1
5521
$ pgrep -l init
1 init
5521 xinit
$ pgrep -fl init
1 init [2]
5521 xinit /etc/X11/xinit/xinitrc -- /usr/bin/X :0 -nolisten tcp -layout Dual -auth /home/user/.serverauth.5500
$ pgrep -l ^init
1 init
pkill works similarly:
$ sleep 1m &[1] 1662
$ pkill sleep
[1]+ Terminated sleep 1m
$ sleep 1m &
[1] 2224
$ pkill -KILL sleep
[1]+ Killed sleep 1m
$ sleep 1m &
[1] 1764
$ pkill 1m
$ pkill -f 1m
[1]+ Terminated sleep 1m
they should already be installed on debian (as the procps package has a priority of "required") and ubuntu (as with my wife's default install).
don't use ps -A | grep, use 'pgrep' instead
type "pgrep firefox" will show you the PID of firefox. Typing "pkill firefox" will close all processes with name "firefox". Typing "pgrep -l firefox" will show you the PID and the process name "firefox"
ps -A | grep is not as powerful
[Edited for language, Admin]
fsm's editorial policy
i actually have nothing to technically add to the parent comment, but the editing of it brings up an interesting point: what are the editorial policies of fsm, specifically regarding user posts?
because i was subscribed to this thread i saw the original post before it was edited and approved by the editor (by way of an emailed "thread subscription update"). while i did not find the original language offensive, i did find the conveyed attitude appalling.
though the single removed word wasn't particularly offensive to me, why not edit out the word and show the edits (eg "ps -A | grep is [not as powerful]")? that would show the community what exactly was edited unlike the current ominous note ("Edited for language, Admin"). or remove the entire post, maybe notifying the original author by email if they have an account (so they can repost a more appropriate comment if so desired).
and what garners an edit? profanity? poor attitude?
just curious as i considered myself a member of a very similar community (based on a linux publication) until an editor removed his own inflammatory post and denied both the post and the removal. that's not an "open" community i want to be part of, so i left.
heck, will this post be removed because i dare question the editors? ;)
The response :-D
Hi,
The post contained useful information, but showed poor attitude.
I found the original language offensive. The trouble is, that person wasn't logged in.
I made the decision that guarantee the spread of (relatively valuable) information, didn't sneakily change comment's contents (I hate that), and respected the poster.
To me, poor attitude is even indirectly call somebody "stupid" - especially if you don't even have an account.
Please note that since we receive a number of comments, we often need to decide quickly - or we would spend the best parts of our days discussing whether a word means "A" or "B" :-D
We very, very, very rarely delete comments (it only happened once, actually) and very occasionally we edit them.
Bye!
Merc.
Great article. You gotta
Great article. You gotta love the doom thing. This really shows how creativity in the free software world can thrive, because this would never be included in a commercial product.
One honorable mention: if you're in top (e.g. to look which processes use a lot of memory/cpu) you can kill an application by hitting "k" and typing in the PID. See
man topor press "?" whilst in top for more info.Thanks for letting me now about pdDooM (not that i'll ever use it, i kinda like the stability of my system).
Good one
This sounds good. I'll have to give the pgrep & pkill a try. Sometimes I've run into areas where I cannot seem to kill a process. Perhaps these two will help.
------
let's all play nice!
Also
If you can't kill a process, try killing it as root (sudo pkill instead of just pkill).
--
Andrew Min
SIGKILL
If you don't get an “Operation not permitted” error, and the process is not killed, you may try sending a SIGKILL:
kill -9 PIDorkill -KILL PIDThe difference is that applications can handle TERM the way they want (some may even save opened files, emails, &c before being closed), but no process can ignore a KILL signal.
That's, no alive process. When a process is already dead (zombie, defunct), it can't answer the signal.
Hmm... I would have guesed
Hmm... I would have guesed that killall command would have been mentioned here. I never use kill but killall every second day.
For example:
killall gnome-panel
or
killall nautilus
are too commands that come handy when tweaking Gnome desktop, and especially if something goes wrong and you end up with a broken gnome-session.
And, no need to know any cryptic process id numbers either, just type killall "processname" and you're done.
htop, atop, blahps
My favorite is htop.sf.net
It runs in the console (ncurses); is light, fast and feature rich.
Now I just need to figure out how to bind Ctrl-Shift-ESC (as in NT/2k/XP) to launch it.
There are also ATComputing.nl/Tools/atop and csincock.customer.netspace.net.au/blahps.htm, but I haven't tried them.
Kill/killall
There is always a solution.Thanx to all who add info which helps me!!
htop, definitely. the best
htop, definitely. the best thing since sliced bread.
Firefox
Hi,
I accidentally ran firefox it was not responding so I knew I had to kill the process and I did it once through the system monitor, well the following day when it happened again I accidentially hit the "hide process" and now and every time I turn the computer I can not see firefox on the system monitor. How do I enable it so that it would show as running on the system monitor again.
unhide process in gnome-system-monitor
i presume you are talking about gnome-system-monitor as it has the functionality you describe (though so could kde, but i wouldn't know).
in gnome-system-monitor (2.14.5, gnome 2.14) select the menu item View -> Hidden Processes (or Ctrl-P). select firefox from the list of hidden processes, press the "Remove From List" button, and press the Close button.