ps
Report a snapshot of current processes.
Description
Displays information about active processes. By default, shows only processes associated with the current user and terminal. Various options control which processes are selected and what information is displayed.
Inputs
/proc/[pid]/stat– PID, comm, state, PPID, pgrp, session, tty_nr, tpgid, utime, stime, nice, num_threads, starttime, vsize, rss/proc/[pid]/status– effective UID, real UID/proc/[pid]/cmdline– full command line arguments/proc/stat– boot time (btime field, for calculating process start times)/proc/meminfo– MemTotal (for %MEM calculation)/proc/uptime– system uptime (for %CPU calculation)/etc/passwd– UID to username mapping
Arguments
Process selection
| Flag | Description |
|---|---|
-A, --all | Select all processes |
-e | Select all processes (identical to -A) |
-a | Select all processes with a controlling terminal, except session leaders |
-x | Include processes without a controlling terminal (typically combined with -a) |
-p, --pid PID,... | Select processes by process ID |
-U, --user USER,... | Select processes by effective user name or UID |
Output format
| Flag | Description |
|---|---|
-u | User-oriented format (typically combined with -a -x for “aux” style) |
-f | Full-format listing |
Behavior
Default mode (no arguments)
Shows processes owned by the current user on the current terminal.
Columns: PID, TTY, TIME, CMD.
PID TTY TIME CMD
1234 pts/0 00:00:01 bash
5678 pts/0 00:00:00 ps
BSD aux mode (-aux or -a -u -x)
Shows all processes in user-oriented format.
Columns: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169356 11892 ? Ss Jan15 0:05 /sbin/init
Full format (-ef or -e -f)
Shows all processes in full format.
Columns: UID, PID, PPID, C, STIME, TTY, TIME, COMMAND.
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jan15 ? 00:00:05 /sbin/init
Computed fields
%CPU
Calculated as:
(utime + stime) / clock_ticks_per_second / elapsed_seconds * 100
Where elapsed_seconds is the time since the process started.
%MEM
Calculated as:
rss_pages * page_size / MemTotal * 100
STAT
A multi-character process state string:
| Character | Position | Meaning |
|---|---|---|
| R, S, D, Z, T, t, X, I | 1st | Process state (running, sleeping, disk sleep, zombie, stopped, tracing stop, dead, idle) |
< | modifier | High priority (nice < 0) |
N | modifier | Low priority (nice > 0) |
s | modifier | Session leader (PID == session ID) |
l | modifier | Multi-threaded (num_threads > 1) |
+ | modifier | In foreground process group (tpgid == pgrp) |
TIME
Cumulative CPU time (utime + stime), formatted as:
HH:MM:SSwhen one hour or moreM:SSwhen less than one hour
START / STIME
Process start time, formatted as:
HH:MMif the process started todayMonDD(e.g.,Jan15) if the process started on a previous day
TTY
Decoded from the tty_nr field in /proc/[pid]/stat:
pts/Nfor pseudo-terminalsttyNfor virtual consolesttySNfor serial terminals?for processes without a controlling terminal
All output uses the cols crate for column alignment.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Failure |