The ps command

The ps command is used to list the processes running on the computer. It can be used to list both your processes and the processes of other users. It its simplest form, you just type ps.

Example 9-1. Basic ps invocation

$ ps
  PID TTY          TIME CMD
 3155 tty2     00:00:00 -bash
 3190 tty2     00:00:00 ps

Here two processes are listed. The first process, whose process ID number (PID) is 3155, is bash. The second process refers to the ps program itself, which also uses a process when it is running.

The ps command can accept many options to alter the way it lists processes and to alter which processes are listed. Among these are a which tells ps to report processes for all users, u which tells ps to report the user that owns each process, and x which indicates to list all processes, even those you ``might normally not be interested in.'' For example:

Example 9-2. Running ps with x option

$ ps x
  545 ?        SN     0:00 ssh-agent -s
 2660 ?        SN     0:00 ssh-agent -s
 2875 ?        SN     0:00 ssh-agent -s
 2961 ?        S      0:00 ssh-agent -s
 2989 tty1     S      0:00 -bash
 3117 tty1     S      0:01 vim jobs.html
 3155 tty2     S      0:00 -bash
 3206 tty2     R      0:00 ps -x

Here, ps has listed the processes that are running on terminal 2 (tty2), but has also listed the processes running on tty1. It has also listed several ssh-agent processes that aren't associated with any terminal at all. On a graphical system, this command would have shown even more processes, including every graphical program being run by the user (at the very least). You can get an idea of all the processes running on a computer with ps aux.