Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

FlagDescription
-A, --allSelect all processes
-eSelect all processes (identical to -A)
-aSelect all processes with a controlling terminal, except session leaders
-xInclude 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

FlagDescription
-uUser-oriented format (typically combined with -a -x for “aux” style)
-fFull-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:

CharacterPositionMeaning
R, S, D, Z, T, t, X, I1stProcess state (running, sleeping, disk sleep, zombie, stopped, tracing stop, dead, idle)
<modifierHigh priority (nice < 0)
NmodifierLow priority (nice > 0)
smodifierSession leader (PID == session ID)
lmodifierMulti-threaded (num_threads > 1)
+modifierIn foreground process group (tpgid == pgrp)

TIME

Cumulative CPU time (utime + stime), formatted as:

  • HH:MM:SS when one hour or more
  • M:SS when less than one hour

START / STIME

Process start time, formatted as:

  • HH:MM if the process started today
  • MonDD (e.g., Jan15) if the process started on a previous day

TTY

Decoded from the tty_nr field in /proc/[pid]/stat:

  • pts/N for pseudo-terminals
  • ttyN for virtual consoles
  • ttySN for serial terminals
  • ? for processes without a controlling terminal

All output uses the cols crate for column alignment.

Exit codes

CodeMeaning
0Success
1Failure