ps

report process status (POSIX)

Syntax:

ps [-A|-a|-d] 
   [-l] [-n node]
   [-F format]
   [-g gid[,gid]... ]
   [-p pid[,pid]... ]
   [-s sid[,sid]... ]
   [-S state[,state]... ]
   [-t term[,term]... ]
   [-u uid[,uid]... ]

Options:

-A
Print information for all accessible processes.
-a
Print information for all processes associated with terminals except for process group leaders.
-d
Print information for all processes except process group leaders.
-F format
Print information according to the format specifications given in format.
[-g gid[,gid]...
Print information only for processes whose groupids are listed.
-l
("el") Print in long format.
-n node
Print information only for processes on the specified node.
-p pid[,pid]...
Print information only for processes whose process IDs are listed.
-s sid[,sid]...
Print information only for processes whose session IDs are listed.
-S state[,state]...
Print information only for processes whose states are listed. (e.g. READY, WAIT).
-t sid[,sid]...
Print information only for processes associated with the terminals listed. Terminals must be in the form [nid]tty_basename, where nid is the node the device exists on, and tty_basename is the basename portion of the controlling terminal's pathname. (e.g. [3]con1 for //3/dev/con1)
-u uid[,uid]...
Print information only for processes whose userids are listed.

Examples:

Emulate the default output from a System V ps command:

ps -F '%+"PID"p %+"TTY"y %+"TIME"t %+"COMMAND"C'

Description:

The ps utility prints information about processes, subject to having the appropriate privilege to obtain information about those processes. With no options, ps prints information about processes associated with the current terminal. The output includes the process ID, terminal name, cumulative execution time, and command name of each process.

The options that use lists (-g, -p, -t, -u) can list multiple items separated by commas or white space, as long as all the items are contained within a single command-line argument. If white space is used, this will require quoting the list when invoking ps from the shell.

The initial set of processes selected by -a, -A, or -d is intersected with the processes selected by the -g, -p, -t, or -u options, if any of the latter are specified.

If none of -a, -A, or -d is specified, ps behaves as though you specified -u your_uid.

Controlling output

To control the content and format of output, you use -F format option, which takes any of the field descriptors listed below. All of these field descriptors, with the exception of %% and %a, are of the form:

The + forces right justification; the - forces left justification. If neither + nor - is specified, the default justification for the descriptor is used. If no title is given for a field, spaces are printed. The [ and ] aren't part of the descriptor; they simply show the optional parts of the descriptor.

The %a field descriptor has the form:

You can use the optional width for limiting the length of what is printed for this field.

Any text included between the field descriptors is printed on all lines, including the header line.

Field descriptors:

%%
A literal % character.
%a
The command with all its arguments as a string.
%b
The process that this process is blocked on.
%c
The name of the command (argv[0] value) as a string.
%C
The ratio of CPU time used (%x) to CPU time available, expressed as a percentage.
%d
The current working directory of the process.
%e
The initial environment of the process.
%f
The flags of the process.
%g
The real groupid of the process.
%G
The effective groupid of the process.
%p
The decimal value of the process ID.
%P
The decimal value of the parent process ID.
%n
The decimal value of the process's nice value.
%N
The decimal value of the process's priority.
%r
The decimal value of the process groupid.
%s
The decimal value of the session ID.
%S
The process state of the process.
%t
In the POSIX locale, the elapsed wall clock time of the process in the form:

[dd-]HH:MM:SS

The dd field is not shown if less than one day.

%T
In the POSIX locale, the start time of the process in the form:
  • [dd-]HH:MM:SS
The dd field gives the number of days before the current date that have elapsed since the process started (not shown if dd is less than one day).
%u
The real userid of the process. If the userid is present in the /etc/passwd file, a textual userid is printed; otherwise, a decimal numeric userid is printed.
%U
The effective userid of the process (see %u).
%x
In the POSIX locale, the cumulative CPU time of the process in the form:
  • [dd-]HH:MM:SS
The dd field is not shown if less than one day.
%y
If a controlling terminal is present, the name of the terminal, consisting of the node ID followed by the tail of the device pathname.
%z
The size of the process in (virtual) memory in kilobytes, expressed as a decimal integer. Shared code or segments are not accounted for.

Exit status:

0
Successful completion.
>0
An error occurred.

See also: