Solaris Advanced User's Guide

Processes and PIDs

After your system interprets each command, the system creates an independent process with a unique process identification number (PID) to perform the command. The system uses the PID to track the current status of each process.

What Commands Are Running Now (ps)

Use the ps command to see what processes are currently running.The ps command shows the process identification number (listed under PID) for each process you own, which is created after you type a command. This command 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).

If you add the -l option to the ps command, the system displays other process information, including the state of each running process (listed under S). The following list defines the codes used to describe processes.

Note that while ps is running, the status of an individual process can change. Since the ps command gives you only a snapshot of what's going on at the moment you issue the command, the output is only accurate for a split second after you type the command.

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

Terminating Processes (pkill)

Most window environments have a tool for managing processes. See the tool's online help if you need information on using it.

You can use the pgrep and pkill commands to identify and stop command processes that you no longer want to run. These commands are useful when you mistakenly start a process that takes a long time to run.

To terminate a process:

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

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

The following example illustrates how to find all the processes with a specific name (xterm) and terminate the xterm process that was started last.

$ pgrep xterm
$ pkill -n 18210

If you need to forcibly terminate a process, use the -9 option to the pkill command.

$ pkill -9 -n xterm