Skip to content

ps Command Cheat Sheet

ps (process status) displays information about a selection of the active processes.


Synopsis

ps [options]

Common Styles

ps accepts three styles of options: 1. Unix (preceded by -): ps -ef 2. BSD (no dash): ps aux 3. GNU (long options): ps --pid 1234


"Standard" Commands

BSD Syntax (Most Common)

ps aux
- a: All users' processes (attached to a terminal). - u: User-oriented format (shows User, CPU%, Mem%). - x: Processes usually not attached to a terminal (daemons).

Unix Syntax

ps -ef
- -e: Select all processes. - -f: Full-format listing.


Custom Formatting (-o)

Create your own output columns.

ps -eo pid,user,%mem,%cpu,comm

Sorting

Sort by memory usage (highest first).

ps aux --sort=-%mem | head
Sort by CPU usage.

ps aux --sort=-%cpu | head

Process Trees

See parent-child relationships.

ps -ely --forest
# OR
ps axjf

Process States (STAT Column)

  • R: Running or runnable.
  • S: Sleeping (interruptible wait).
  • D: Uninterruptible sleep (usually I/O). Cannot be killed.
  • Z: Zombie (terminated but parent hasn't reaped it).
  • T: Stopped (suspended).
  • <: High priority (not nice).
  • N: Low priority (nice).

Find Specific Process

Generally pgrep is better, but with ps:

ps -C chrome
Or by PID:
ps -p 1234 -F
(-F: Extra full format).


Show Threads (-L)

Listing threads (LWP - Light Weight Process).

ps -eLf
Output includes LWP (Thread ID) and NLWP (Number of threads).


Notes

  • Zombie Processes: You cannot kill a zombie. You must kill its parent to force a cleanup.
  • Top consumers: ps aux --sort=-%mem | head -n 5.