OpenWindows Advanced User's Guide

5.2 Processes and PIDs

After each command is interpreted by the system, an independent process, with a unique process identification number (PID), is created to perform the command. The system uses the PID to track the current status of each process.

5.2.1 What Commands Are Running Now (ps)

Use the ps command to see what processes are currently running. In addition to showing the process identification number (listed under PID) for each process you own (created as a result of a command you typed), ps also shows you the terminal from which it was started (TTY), the cpu time it has used so far (TIME), and the command it is performing (COMMAND).

Adding the -l option to the ps command displays a variety of other information about the processes currently running, including the state of each process (listed under S). The codes used to show this are as follows:

Note that while ps is running, things can change. Since the ps command gives you only a snapshot of what's going on, it's only true for a split second after you type the command. The information may not be completely accurate by the time you see it.

The ps(1) command has more options than those covered here. Refer to the man Pages(1): User Commands.

5.2.2 Terminating Processes (kill)

The kill command provides you with a direct way to stop command processes that you no longer want. This is particularly useful when you make a mistake typing a command that takes a long time to run.

To terminate a process:

  1. Type ps to find out the PID(s) for the process(es).

  2. Type kill followed by the PID(s).

The following example illustrates this procedure:

$ ps
1291   co     0:12    -bin/csh (csh)
3250   p0     0:00    ps
1286   p1     0:05    -bin/csh (csh)
3248   p1     0:05    vi commands
$ kill 1291
[1}  Terminated       -bin/csh/ (csh)

Note that a faster way of determining the right PID is to pipe ps output through grep as follows:

$ ps | grep commandname

where commandname is the name of the command process you want to stop.

If you need to forcibly terminate a process, you can use the -9 option to the ps command as follows:

$ kill -9 PID#

where PID# is the process identification number of the process you want to stop.