Dealing with Runaway Processes

Have you ever been using your Linux distro and suddenly found a program won’t close? It’s frustrating when an application hangs. In Windows, one could right click on the taskbar and choose “Task Manager” and kill the hanging process (which doesn’t always work BTW). In Linux, you can also kill these hanging processes.

First, if you’re using KDE press Control-Escape. This will give all processes in a handy window called the KDE System Guard. Clicking the column heading for “System %” so the arrow on it appears facing up will sort the processes from highest system percentage to lowest. Find the process that seems to be hogging up all the resources (or if you know the name of the process, highlight that) and then hit the kill button. Your process should end it’s routines and exit.

You can also check out which program is hogging up your virtual memory with its process which can also slow things up. Clicking on the column “VmSize” and sorting largest to smallest will allow you to see this and select which process to kill. I often elect to select only user processes using the drop down menu at the top right hand corner of the KDE System Guard. Doing this filters out all system files and shows any hanging applications that are initiated by the user (which is often what is hanging for me).

Don’t worry if you see the same process more than once (for example, Apache or php may have multiple entries if you run a webserver…this is normal). If you’re using Gnome, you’ll either have to use the console method I explain below or launch the Gnome System Manager to get things rolling. Since I don’t use Gnome, I won’t cover the Gnome System Manager here.

Another way you can do things…especially if all Xwindows (KDE, Gnome, Fluxbox, etc) have frozen or are sluggish is to drop to a console. You can do this by killing the Xserver or by dropping to a console. You can press Alt-F2 or Alt-F3 and get directly to a console. Login as root. Now let’s take a look and see what processes are hogging up resources. Kill the Xserver and drop to a console by hitting Control-Alt-Backspace. For our purposes, I’ll assume you’ve made it to the console now.

There’s a quick console way of finding exactly what is consuming the most of your PC as far as processes are concerned. Using the the ‘top’ command will display those processes that are beasts and allow you to take note of them. Look for the process taking up the most CPU% (which should appear at the ‘top’ of your ‘top’ output). Pay specific attention to the PID column of that high CPU% item and make a note of it. This is the process ID number and every program running on a Linux box is assigned one by the Kernel. We’ve found the one making problems for us and have recorded the PID so let’s slay it. Hit Control-C to stop the top command and then type:

kill PID

Where PID is the process ID number you made a note of before. You may not get confirmation that the task has been immediately killed so let’s see if it is still running. We may not get the information we need by using top again since it is mainly for finding the higher consuming processes aka runaways. Instead, let’s use the ps command.

ps aux | more

This command outputs all processes in a nice way…using the | and ‘more’ command allows you to paginate the output so that if there are a TON of processes, you can use the spacebar or arrow keys to page down (you can do that with any command too BTW). Now look for that PID that we just killed in the second column and see if it is there. You could also get creative and use:

 ps aux | grep PID

Where PID is once again the PID you killed. The grep command will search through the results and echo back to you any matching entries it finds. If you didn’t find anything and couldn’t match your PID to that of any displayed in your ps aux command, you just successfully killed that beastly process. As always, for more information, please see the man pages (e.g. man ps or man top).

Hopefully, this allows you to more efficiently manage your processes…runaway or normal. If I’ve printed an error, please let me know via the comments below or if there is a more efficient way of doing things let me know there as well…I’m always open to improvement.

UPDATE: Please checkout the comments section for a few more tips on killing processes!

UPDATE2:  Reader Scott M writes in the comments below “You don’t have to use the PID. You can use the -f option.  e.g. if there are multiple instance of SomeProgram, you can kill them all with one command:

pkill -9 -f SomeProgram”  Thanks Scott!

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.


devnet has been a project manager for a Fortune 500 company, a Unix administrator, a Technical Writer, and a System Analyst during his 10 years working with Technology.

  • Vox

    Don’t forget the GUI kill…in KDE (probably in every other DE/WM, but am not sure), you hit CTRL-ALT-ESC and your cursor turns into a skull-and-bones cursor…left-click the offending window and boom, kill -9’ed :)

  • Roy Schestowitz

    The following may be quicker.

    killall -HUP [application-name]

  • Kevin Brooksby

    Dont forget about the handy pgrep and pkill variations as well. These have bailed me out a time or two.

  • LOKE

    Not all runaway processes are easily killed, some resist the kill PID and need another try.
    My way do deal with them is
    kill PID
    wait a few seconds
    if it is still alive:
    kill -2 PID
    wait a few seconds
    if it is still alive:
    kill -1 PID
    Now it should be dead and gone, but there is always the last, dirty resort:
    kill -9 PID

    Note, that kill -9 cuts the throat without giving the sick process any chance of cleaning up after itself (sockets/temp/children a.o.)

  • Scott M

    You don’t have to use the PID. You can use the -f option.
    e.g. if there are multiple instance of SomeProgram, you can kill them all with one command:
    pkill -9 -f SomeProgram

  • devnet

    Thanks much for the input! I’ll be updating the post with your info and a link to your site :)

  • rugs

    Yet another reason that shows why Linux is just more powerful. There are multiple ways to do something – and being able to do it for console is a huge bonus. Doubt you could kill programs through Windows’ command prompt!
    How do you do it in Ubuntu though? I’m still relatively new to this – I presume that Ubuntu uses Gnome. It’s a pity you didn’t put any details for Gnome down, that would have been helpful.

  • Jayesh

    How will you identify that the process is really hung and not running. In top you ppl only see the status of it like “S” sleeping.. You cant check from ps aux or top or kill commend about the runnning process status if that’s hung or not..