Processes are the tasks that a computer handles. Every time you run any command, it appears on the computer as a process, with attributes and identifiers. If a process runs amok, you need to do something about it. Thus, commands for managing processes are integral to any good operating system.
Starting a process from the command line is the easiest thing to do on any computer. Just type the name of the process you want to run. For example, on a Unix computer the command /usr/bin/firefox should run the firefox browser. On windows, the corresponding command would be "c:\program files\firefox\communicator\program\firefox.exe". It is sometimes more difficult to terminate a process that has run amok.
You cannot manage processes from the command line in Windows. Actually, if you purchase additional software (the famous "Resource Kit") from Microsoft, you can, but in the OS you pay several hundred dollars for, there are no facilities for managing processes from scripts or a command line. To its credit, Microsoft does provide limited GUI tools for managing processes.
In Unix the basic command for monitoring processes is called ps (process status). Typing ps by itself lists the processes that you own from your current session on the computer.
PID TTY TIME CMD
25506 pts/4 00:00:00 csh
26288 pts/4 00:00:00 ps
The first number is the process ID number. The pts/4 identifies the "terminal" associated with the process, the next number tells how much processor time the the process has used, and the name of the program that started the process appears at the end of the line.
If you need more information, you may apply switches to the ps command. For example, the command ps u gives
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
dbcooper 25506 0.0 1.3 2988 1684 pts/4 S 09:53 0:00 -csh
dbcooper 26468 0.0 0.6 2640 0796 pts/4 R 10:45 0:00 ps u
The u stands for "user information". This time the process ID appears second on the line. For more information, you may use the ever-popular "ps aux" command. This lists all processes currently executing on the computer.
The easiest way to kill a process that has taken over your command line is to press <ctrl>+c. The "control-c" combination interrupts any process that is running in your shell. Thus if you ran firefox on a Unix machine as described earlier on this page, typing <ctrl>+c on your command line should kill it.
It is possible to run processes that are not associated with your command line. In Unix these are called "background processes". You can make a process run in the background in Unix by adding an ampersand (&) at the end of the line. Thus if you wanted to run firefox from the command line you would type
Sometimes we forget to add the ampersand. In that case we can still put the job in the background by first stopping it and then forcing it into the background. To stop a job running in the foreground (that is, controlling your command line) simply press the <ctrl> and z keys simultaneously. This stops the job completely, so that it is in limbo. After that, you may type the command bg on your command line to cause the job to start again, but in the background. If ever you want to type input to the process, you can bring it back to the foreground by typing fg.
There are no corresponding commands in Windows, but it does seem to force graphical applications such as firefox to the background automagically. There is no way to bring such processes to the foreground.
Suppose that you have started a background Unix firefox session that has hung up, that is, it seems not to respond to any input from anybody anymore. Once you know the process ID of the firefox process you can kill it using (what else?) the kill command. We recommend using the -9 switch with this command always.
shuksan> ps aux |grep firefox
dbcooper 24154 0.2 6.3 23736 8080 ? S 08:31 0:20 /usr/lib/firefox
dbcooper 26766 0.0 0.4 1620 600 pts/4 S 11:01 0:00 grep firefox
shuksan> kill -9 24154
shuksan> ps aux | grep firefox
dbcooper 26769 0.0 0.4 1620 600 pts/4 S 11:02 0:00 grep firefox
We ran ps aux to find the process details, but used the grep command to pick out the lines involving firefox. The second process "grep firefox" is just the process to carry out the command we gave. Looking at the line for "/usr/lib/firefox" we see that the process ID is 24154. Thus, we give the command kill -9 24154 to kill firefox. When we look again for firefox processes we see that the one that had ID 24154 is now dead.