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.
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:
O - Process is running on a processor.
Z - Zombie state: Process terminated and parent not waiting.
T - Traced: Process stopped by a signal because parent is tracing it.
X - SXBRK state: Process is waiting for more primary memory.
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.
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:
The following example illustrates this procedure:
$ ps PID TTY TIME COMMAND 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.