The ps command produces a report summarizing execution statistics for current processes. The bare ps command lists the process ID, the terminal the command was started from, how much CPU time it has used, and the command itself. The output looks something like this (it differs from system to system):
PID TT STAT TIME COMMAND 1803 p5 IW 0:00 -csh (csh) 1883 p5 IW 0:04 vi outline 1811 p6 IW 0:01 -csh (csh) 5353 p6 TW 0:01 vi 4890
By default, ps lists only your own processes. There are many times, though, when it's desirable to have a more complete listing with a lot of data about all of the processes currently running on the system. The options required to do this differ between BSD UNIX and System V. Under BSD UNIX, the command is ps -aux, which produces a table of all processes, arranged in order of decreasing CPU usage at the moment when the ps command was executed. [The -a option gives processes belonging to all users, -u gives a more detailed listing, and -x includes processes that no longer have a controlling terminal (38.6). -TOR ] It is often useful to pipe this output to head (25.20), which will display the most active processes:
%ps -aux | head -5
USER PID %CPU %MEM SZ RSS TTY STAT TIME COMMAND martin 12923 74.2 22.5 223 376 p5 R 2:12 f77 -o foo foo.F chavez 16725 10.9 50.8 1146 1826 p6 R N 56:04 g94 HgO.dat ng 17026 3.5 1.2 354 240 co I 0:19 vi benzene.txt gull 7997 0.2 0.3 142 46 p3 S 0:04 csh
The meanings of the fields in this output (as well as others displayed by the -l option to ps) are given in Table 38.1.
The first line of this output shows that user martin is running a
FORTRAN compilation (f77
).
This process has
PID (38.3)
12923 and is currently either running or
runable. User chavez's process (PID 16725), executing the program
g94, is also running or runable, though at a lowered priority.
From this display, it's obvious who is using most system resources at this
instant: martin and chavez have about 85% of the CPU and 73% of
the memory between them. However, although it does display total CPU time,
ps does not average the %CPU
or %MEM
values over time
in any way.
Column[3] | Contents |
---|---|
USER (BSD) | Username of process owner. |
UID (System V) | Username of process owner. |
PID | Process ID. |
%CPU | Estimated fraction of CPU consumed (BSD). |
%MEM | Estimated fraction of system memory consumed (BSD). |
SZ | Virtual memory used in K (BSD) or pages (System V). |
RSS | Real memory used (in same units as SZ). |
TT, TTY | Terminal port associated with process. |
STAT (BSD), | Current process state; one (or more under BSD) of: |
S (System V) | |
R: Running or runnable. | |
S: Sleeping. | |
I: Idle (BSD). Intermediate state (System V). | |
T: Stopped (12.8). | |
Z: Zombie process (38.16). | |
D (BSD): Disk wait. | |
P (BSD): Page wait. | |
X (System V): Growing: waiting for memory. | |
K (AIX): Available kernel process. | |
W (BSD): Swapped out. | |
N (BSD): Niced (39.9, 39.11):execution priority lowered. | |
> (BSD): Execution priorityartificially raised (39.11). | |
TIME | Total CPU time used. |
COMMAND | Command line being executed (may be truncated). |
STIME (System V) | Time or date process started. |
C (System V), | Short term CPU-use factor; used by scheduler for |
CP (BSD) | computing execution priority (PRI below). |
F | Flags associated with process (see ps manual page). |
PPID | Parent's PID. |
PRI | Actual execution priority (recomputed dynamically). |
NI | Process nice number (39.9). |
WCHAN | Event process is waiting for. |
[3] Some vendors add other fields, such as the processor number for multiprocessors and additional or different process states (as in the AIX K field). These codes may differ from vendor to vendor: for example, the 0 code under Stardent UNIX means a process that is actually running (and R means runable) while 0 under AIX means a nonexistent process.
A vaguely similar listing is produced by the System V ps -ef command:
$ps -ef
UID PID PPID C STIME TTY TIME CMD root 0 0 0 09:36:35 ? 0:00 sched root 1 0 0 09:36:35 ? 0:02 /etc/init ... gull 7997 1 10 09:49:32 ttyp3 0:04 csh martin 12923 11324 9 10:19:49 ttyp5 56:12 f77 -o foo foo.F chavez 16725 16652 15 17:02:43 ttyp6 10:04 g94 HgO.dat ng 17026 17012 14 17:23:12 console 0:19 vi benzene.txt
The columns hold the username, process ID, parent's PID (the PID of the process that created it), the current scheduler value, the time the process started, its associated terminal, its accumulated CPU time, and the command it is running. Note that the ordering is by PID, not resource usage.
AIX's version of the ps command supports both BSD
and System V options. The BSD options are not preceded by a
hyphen (which is a legal syntax variation), and the System V options
are. Thus, under AIX, ps -au
is not the same as
ps au
. The command is the System V version, however, even if
its output is displayed with the BSD column headings. Thus,
ps aux output is displayed in PID
rather than
%CPU
order.
ps is also useful in pipes; a common use is:
%ps -aux | grep chavez
to see what user chavez has currently running. [Under System V,
use ps -u chavez
. -JP]
- from O'Reilly & Associates' Essential System Administration, Chapter 7