When you run a program, a copy of the program is loaded into the computer's memory and is run from there. A running program is called a process. It is easy to run many processes at once, and to lose track of some of them, especially when you are writing your own programs and when these programs spawn further processes. This can be troublesome as it can consume excessive amounts of computer resources and cause you to breach the terms and conditions of your account usage. See Why is my Account Access Denied? (section 1.6.2, page ) and The Yellow Form (section 1.6.3, page ).
You can find out what processes you have running using the ps command, and you can stop runaway processes using the kill command.
To use the ps command in a fairly simple way, type
% ps -u
This will produce an output something like:
ives:/home/www/lib/html> ps -u tchambers PID TTY S TIME CMD 1853 ?? S 0:03.61 /usr/local/bin/xdvi -paper a4r -geometry 1050x 4803 ?? I 0:00.16 (dns helper) 9118 ?? S 0:11.43 /usr/local/bin/.netscape4 -no-about-splash 11742 ?? I 0:00.24 /bin/ksh /import/bizet/3/tchambers/.xsession 12307 ?? S 0:00.10 xclock -digital 17697 ?? S 0:00.91 /usr/local/X11/bin/twm 30481 ?? I 0:00.06 /usr/local/bin/checkmail 32565 ?? I 0:00.65 gs -sDEVICE=x11 -dNOPAUSE -q - 200 ttypa I + 0:03.24 pine -i 25844 ttypc S 0:08.04 emacs primer.tex 32093 ttypc I + 0:00.48 ae 16503 ttyq2 S 0:00.44 ae
The number in the `PID' column is the Process ID Number which is used to identify the process and is what you need to know to be able to kill a process. The `TTY' column shows which terminal (or x-window) the process output is displayed in. The `S' column is the process status. The `TIME' column shows how much cpu time the process has consumed. This is a good indicator of how resource hungry the process is. The `CMD' column lists the command which launched the process, or the name of the program.
The ps command has many more capabilities. You should read the manual (type man ps).
Note: ps can behave differently depending on the architecture you are using.
To kill a process, you type
The kill command won't tell you whether or not it was successful -- you should run the ps command again to verify that the process you wanted to kill has indeed been killed. If you have a process which won't die, you can use a more insistent form of the kill command:
% kill -9
You should avoid using this version if you can because it does not give the process a chance to `tidy up', and can therefore lead to problems.Loc Van Huynh 2007-03-15