← Full reference

ps

Process list — PID, parent, owner, memory, CPU, state and full command line

ps takes a snapshot of processes at the moment it runs and prints a table. Unlike top, it doesn't refresh — but its output is easy to filter and parse in scripts.

Syntax

ps [options]

ps from procps has two option styles, and they can be mixed: UNIX — with a dash (ps -ef), BSD — without a dash (ps aux). The same letter means different things in them: ps -a and ps a are not the same. Without options ps shows only the processes of the current terminal.

Which processes to show

OptionWhat it selects
-e / -Aall processes
axall processes (BSD style; a — all users, x — also those without a terminal)
-p 1,42 / p 42by PID
-C nameby executable name (exact match, no path)
-u userby effective user; -U — by real user
-g / --sid / -sby process group / by session
--ppid 1children of the given process
-t pts/0by terminal
-Ninvert the selection

What to show

OptionWhat it does
-ffull format: UID PID PPID C STIME TTY TIME CMD
-Fextra full: plus SZ RSS PSR
uBSD "user" format: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
-llong format with F S PRI NI WCHAN
-o field,fieldcustom columns; -o pid= — no header; -o user:20 — column width
-O fielddefault columns plus the given ones
--no-headers / hno header line
--sort=-%mem,pidsorting; - before a field — descending
--forest / fprocess tree (indentation and \_)
-Hhierarchy by indentation
-L / -Tshow threads (columns LWP/SPID, NLWP)
ww / -wwdon't truncate long command lines

Columns

Column (-o name)Meaning
PID (pid), PPID (ppid)process ID and its parent's ID
USER/UID (user, uid)owner (effective)
%CPU (%cpu)CPU share averaged over the process's whole lifetime, not "right now"
%MEM (%mem)share of physical memory (by RSS)
RSS (rss)physical memory in use, KiB
VSZ (vsz)virtual memory, KiB (including what isn't loaded)
TTY (tty)terminal; ? — process without a terminal (a daemon)
STAT (stat)state, see below
START/STIME (start, stime)start time; lstart — full date
ELAPSED (etime, etimes)how long the process has lived: [[dd-]hh:]mm:ss / in seconds
TIME (time)total CPU time
NI (ni), PRI (pri)nice (−20…19) and priority
CMD/COMMAND (cmd, args)full command line; comm — name only (up to 15 characters)
WCHAN (wchan)kernel function the process is sleeping in
NLWP (nlwp)number of threads

STAT codes

CodeMeaning
Rrunning or runnable
Ssleeping, waiting for an event (the usual state)
Duninterruptible sleep — usually waiting for disk or network; signals, even KILL, have no effect until it leaves this state
Zzombie <defunct>: exited, but the parent hasn't collected the exit code yet
T / tstopped (SIGSTOP, Ctrl+Z) / stopped by a debugger
Iidle kernel thread
ssession leader
< / Nhigh / low priority (nice)
lmultithreaded
+in the terminal's foreground process group

Examples

# all processes, the two classic variants
ps aux
ps -ef

# custom columns, sorted by memory, top 10
ps -eo pid,ppid,user,%mem,rss,cmd --sort=-%mem | head -n 11

# processes named nginx
ps -C nginx -o pid,ppid,stat,cmd

# PID only, no header — for substitution in a script
ps -C cron -o pid=

# who is the parent of a process and when it started
ps -o ppid=,lstart= -p 1234

# process tree
ps -ef --forest
ps axf -o pid,args

# children of process 1
ps --ppid 1 -o pid,cmd

# zombies
ps -eo pid,ppid,stat,cmd | awk '$3 ~ /^Z/'

# how many seconds a process has been alive
ps -o etimes= -p 1234

# grep the list without matching the grep line itself
ps aux | grep '[n]ginx'

Pitfalls

  • ps aux | grep name also finds grep itself. Use pgrep, ps -C name or the square-bracket trick: grep '[n]ginx'.
  • %CPU is an average over the process's lifetime. A process that has just started loading the CPU may show 0.5%. Look at current load in top.
  • -C searches by executable name, not by arguments: ps -C python3 finds Python scripts, but ps -C myscript.py doesn't. For arguments — pgrep -f.
  • comm is truncated to 15 characters, and the name can be spoofed. The full line is in args/cmd.
  • A zombie can't be killed with kill: it's already dead. It disappears when the parent calls wait or exits itself.
  • The output is a snapshot. Between ps and the next command a process may exit and its PID may go to another one.
  • BSD and UNIX options differ: ps -u root means root's processes, while ps u is an output format.

See also

pgrep · kill · proc · grep