Jump to content

ps (Unix)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Spoon! (talk | contribs) at 08:28, 10 April 2006 (External links). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


In most Unix-like operating systems, the ps command line program gives a snapshot of the currently running processes, including ps itself.

ps has many options. On operating systems that support the UNIX and POSIX standards, ps is commonly run with the options -ef, where "-e" selects every process and "-f" chooses the "full" output format. Another common option on these systems is -l, which specifies the "long" output format.

Most systems derived from BSD fail to accept the POSIX and UNIX standard options because of historical conflicts (for example, the "e" or "-e" option will cause environment variables to be displayed). On such systems, ps is commonly used with the non-standard options aux, where "a" lists all processes on a terminal, including those of other users, "x" lists all processes without controlling terminals and "u" adds the controlling user for each process. Note that, for maximum compatibility when using this syntax, there is no "-" in front of the "aux".

Another Unix utility named top provides a real-time view of the running processes.

The following is an abridged list of valid options to run with the ps command:

SIMPLE PROCESS SELECTION
-A              Select all processes. Identical to -e.

-N              Select all processes except those that fulfill the specified
                conditions. (negates the selection) Identical to --deselect.

T               Select all processes associated with this terminal. Identical
                to the t option without any argument.

-a              Select all processes except session leaders (see getsid(2))
                and processes not associated with a terminal.

a               Lift the BSD-style "only yourself" restriction, which is
                imposed upon the set of all processes when some BSD-style
                (without "-") options are used or when the ps personality
                setting is BSD-like. The set of processes selected in this
                manner is in addition to the set of processes selected by
                other means. An alternate description is that this option
                causes ps to list all processes with a terminal (tty), or to
                list all processes when used together with the x option.

-d              Select all processes except session leaders.

-e              Select all processes. Identical to -A.

g               Really all, even session leaders. This flag is obsolete and
                may be discontinued in a future release. It is normally
                implied by the a flag, and is only useful when operating in
                the sunos4 personality.

r               Restrict the selection to only running processes.

x               Lift the BSD-style "must have a tty" restriction, which is
                imposed upon the set of all processes when some BSD-style
                (without "-") options are used or when the ps personality
                setting is BSD-like. The set of processes selected in this
                manner is in addition to the set of processes selected by
                other means. An alternate description is that this option
                causes ps to list all processes owned by you (same EUID as
                ps), or to list all processes when used together with the
                "a" option.

--deselect      Select all processes except those that fulfill the specified
                conditions. (negates the selection) Identical to -N.

OTHER INFORMATION
L               List all format specifiers.

-V              Print the procps version.

V               Print the procps version.

--help          Print a help message.

--info          Print debugging info.

--version       Print the procps version.

An example of the ps command is:

tux ~ # ps
  PID TTY          TIME CMD
 7431 pts/0    00:00:00 su
 7434 pts/0    00:00:00 bash
18585 pts/0    00:00:00 ps

The ps command can also be used in conjunction with the grep command to find information about one process, such as its process id. An example of this is:

tux ~ # ps -A | grep firefox-bin
11778 ?        02:40:08 firefox-bin
11779 ?        00:00:00 firefox-bin
11780 ?        00:00:18 firefox-bin
11782 ?        00:00:12 firefox-bin
12855 ?        00:00:00 firefox-bin
17438 ?        00:00:00 firefox-bin
17439 ?        00:00:00 firefox-bin

See also