Important ps Options

The most important tool for learning about your processes is ps. This tool displays a list of processes, along with assorted information about them, such as their PIDs, PPIDs, CPU time consumption, and so on. Precisely what information is displayed depends on the options you pass to ps. These options also determine what processes are displayed—those run from the current shell, those run by the current user, all processes, or some other set.

Although ps is a common Unix utility, it varies substantially from one OS to another, in terms of its options and output. Linux's ps supports several different option formats:

Unix98 Options These options are single-character in nature and must be preceded by a dash, as in -a. You can combine multiple Unix98 options, as in -ax.

BSD Options These options are single-character in nature and must not be preceded by a dash. You can combine multiple BSD options, as in ax.

GNU Long Options These options are strings of several characters and are preceded by two dashes, as in -forest. You can combine GNU long options by separating them with a space, as in -forest -headers.

Some options from each format type produce similar effects, and even within a given class, different options may produce overlapping sets of information. Therefore, if you want to learn something specific, there may be many ps command variants that will do the trick. Some options take parameters, such as a user ID (UID) number. For Unix98 and BSD options, you separate these parameters from their options with a space; for GNU long options, you use an equal sign (=). Table 14.1 summarizes the most important ps options.

Table 14.1: Important ps Options



Required Parameters

-A or-e

Displays all processes


-N or-deselect

Reverses meaning of process-selection options



Displays all processes on ttys except session leaders



Displays all processes except session leaders



Displays all processes run from the current terminal



Displays all processes run from the current terminal, including those run by other users


Displays only actively running processes



Displays processes without associated ttys



Displays processes by command name

Process name

-G or-Group

Displays processes by the real user's GID

GID number or group name


Displays processes by the effective group ID

GID number or group name

-U or-User

Displays processes by the real user's UID

UID number or username

-u, U, or-user

Displays processes by the effective user ID

UID number or username


Displays processes by session leader or GID

GID number or group name

-p, p, or-pid

Displays specified processes

Comma-separated PID list



Required Parameters

-t, t, or-tty

Displays processes belonging to a tty

Tty number

-s or-sid

Displays processes by session number

Session number

-H, f, or-forest

Displays process parent/child relationships


-w orw

Displays wide (132-column) output




Required Parameters


Uses raw CPU time rather than a decaying average for CPU time report


S or-cumulative

Includes dead child data in parent's report


Displays true command name instead of process name


Displays the environment following the command


h or-no-headers

Omits header from output



Displays header information every screen (usually 24 lines)


-m orm

Displays threads


-cols, -columns, or-width

Sets display width

Number of characters

-lines or-rows

Sets display height (used by -headers)

Number of lines

-V or-version

Displays ps version information



Displays command use summary


Note The Unix98, BSD, and GNU long options listed as equivalent in Table 14.1 don't always yield identical outputs.

Many of the options in Table 14.1 modify the information that ps provides about each process. For instance, an option may add a PPID column to the output or change the command column to show options passed to the command. In addition, some options are designed expressly to modify the output. These options are summarized in Table 14.2. The -o, o, and -format options enable you to create your own custom output format by passing codes for the fields you want to see.

Table 14.2: ps Output Field Options


Creates Output Fields


UID, PID, PPID, CPU utilization, start time, tty, CPU time, command


PID, process GID, session ID, tty, CPU time, command


Flags, state, UID, PID, PPID, CPU utilization, scheduling priority, nice value, process address, size in blocks, wait channel, tty, CPU time, command


PPID, PID, process GID, session ID, tty, controlling tty's process GID, status, UID, CPU time, command


Flags, UID, PID, PPID, scheduling priority, nice value, virtual memory size, resident set size, kernel process number, status, tty, CPU time, command


UID, PID, pending, blocked, ignored, caught, status, tty, CPU time, command


Username, PID, percentage of CPU time, percentage of memory, virtual memory size, resident set size, tty, status, start time, CPU time, command


PID, tty, status, CPU time, major page faults, resident text (code) size, data (stack) size, resident set size, percentage of memory, command

Because ps accepts so many options and produces so much output, it can be a challenge to use it to best effect. The fact that a Linux system can run dozens or hundreds of processes makes matters worse, because it can be hard to locate relevant information in a lengthy output. To some extent, you must learn to use ps through experience. Try experimenting with its options and studying its output. To that end, I will present a few simple examples. First, ps without any options:

$ ps PIDTTY 11716 pts/5 21091 pts/5 29092 pts/5 1597 pts/5

TIME CMD 00:00:00 bash 00:00:01 nedit 00:00:02 xfig 00:00:00 ps

This output includes just four columns, and ps displays information only on the portion of the process tree from which it's directly descended—that is, the shell from which it was run (PID 11716, bash), other processes run from that shell (PIDs 21091 and 29092, nedit and xfig), and the ps process itself (PID 1597). All of these processes are run from pts/5 (an xterm window), and none has used much CPU time (even a process that's been running for weeks might use almost no CPU time if it hasn't been called upon to do much work). In this particular example, the ps process has a lower PID than the other processes in the list because PID numbers can, and sometimes do, "loop back," much like a car's odometer ticking over to 0 miles. Despite the lower PID number, ps was run after the other processes.

The u option creates an output format with information geared toward evaluating the demands for system resources placed on the computer by a user's programs:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND rodsmith 11716 0.0 0.3 2688 1216 pts/5 S Jan23 0:00 bash rodsmith 21091 0.0 0.9 6480 3204 pts/5 S Jan27 0:01 nedit /home/rodsm rodsmith 29092 0.0 1.1 6020 3632 pts/5 S Jan28 0:02 xfig f1401 .fig rodsmith 1619 0.0 0.2 2684 780 pts/5 R 16:06 0:00 ps u

This output includes the same four columns as the prior example's output, although the COMMAND column includes command-line options, as well. Interspersed with these columns are others that provide additional information that you can use to help locate processes that are consuming too much memory or CPU time:

%CPU This column displays the percentage of CPU time the process is currently demanding.

%MEM This column displays the percentage of memory that the process is currently using.

VSZ The virtual memory size is the total memory, both RAM and swap, that the process is using.

RSS The resident set size is the amount of RAM that the process is using, not counting kernel data structures.

STAT This column displays the status—S for a sleeping, or idle, process, and R for a running process.

START This column displays the process start time, given as a time in 24-hour format or a date for processes that have been running for over a day.

One very helpful set of options is -aux; if you type ps -aux, ps produces output like that just described for every process running on the computer. Even a lightly loaded system is likely to have dozens of processes running, so you may want to pipe the output through less, redirect it to a file, or use grep to trim the output based on a process name you want to examine.

0 0

Post a comment