# Killing Processes

## Introduction

This is a step-by-step guide to cleaning up runaway or stuck processes for computer novices. Sometimes computer programs get out of control and start using up all the machine's CPU time, slowing the computer down for everyone else who's trying to use it. This most often happens when firefox or acroread (Acrobat Reader) crashes. Sometimes programs crash or shut down uncleanly, and don't necessarily eat CPU but may make it impossible to restart that program. In either case killing the problematic process will make the computer work better.

If you don't have any jobs running, type "reboot" to reboot your computer (this won't work if someone else is using it). Otherwise, the procedure is first to find the numerical "process ID" or PID and then to kill the unwanted process(es) with the kill command.

## Finding runaway processes

You can check whether you have any runaway processes by typing "top", which which will give you a regularly updated display of the processes, beginning with the ones using the most CPU. Press "q" to exit top. Here is an example of the output from the "top" command. Note that the PID is in the first column.

top - 11:25:10 up  2:27,  3 users,  load average: 0.06, 0.14, 0.30
Tasks: 256 total,   5 running, 251 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3%us,  0.3%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3806916k total,  1540960k used,  2265956k free,   263284k buffers
Swap: 10485752k total,        0k used, 10485752k free,   549076k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
2571 root      20   0  130m  24m  11m R  1.7  0.7   3:29.51 Xorg
2952 eva       20   0  400m  15m  11m S  0.3  0.4   0:03.80 wnck-applet
3230 eva       20   0  384m  31m  13m S  0.3  0.9   0:10.04 emacs
1 root      20   0 23600 1648 1312 S  0.0  0.0   0:00.54 init
2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
3 root      RT   0     0    0    0 S  0.0  0.0   0:00.06 migration/0
4 root      20   0     0    0    0 S  0.0  0.0   0:00.12 ksoftirqd/0
5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
7 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1
8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1
9 root      20   0     0    0    0 S  0.0  0.0   0:00.11 ksoftirqd/1
10 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/1
11 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/2
12 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/2
13 root      20   0     0    0    0 S  0.0  0.0   0:00.06 ksoftirqd/2
14 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/2


On this machine, nothing is using very much CPU. You can tell this from the line where it says "99.3% idle" and from the very low numbers in the "%CPU" column.

## Finding other processes

Use this procedure when a program is not working, to find and kill any stuck instances of the program. The command ps uxwww will give a complete list of all your processes, and if you pipe it through grep you can select only processes with a certain name. E.g., to find all your Firefox processes

ps uxwww | grep firefox


The PID is in the second column.

(The list may include the grep command itself. Just ignore that process. Attempts to kill it will fail as it has already terminated.)

## How to kill processes

The command to kill a process is

kill PID

To make sure the process has terminated, repeat the command and you should get a "no such process" error message. If not, you need to kill the process more forcefully:

kill -9 PID

If necessary, repeat the procedure of finding and killing processes until all troublesome processes are dead.

If lots of processes with the same name need killing then the killall command is useful.

killall PROCESS-NAME
killall -9 PROCESS-NAME


## Tidying up

If it is Firefox which ran away, then you may need to locate and remove any leftover "lock" files before the browser will start working again. Search your Firefox profile directory ~/.mozilla/firefox/blahblah.default for files with "lock" in their name, including the hidden file .parentlock.

cd ~/.mozilla/firefox/*.default
ls -a


If files called lock or .parentlock are present, delete them.

Alternatively, use our local command unlock-firefox.