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 Command Guide for a Snapshot of Running Processes

This guide helps you understand and use the ps command, the standard way to report what processes are running on your system right now.


What is ps, and Why Use It?

The ps command prints a snapshot of the processes the system knows about — their IDs, what they are doing, how much memory they use, and who started them. Its name literally means “process status.” Unlike top, which keeps refreshing, ps shows you one frozen moment and exits.

Why Learn ps?

  • The first move when something is wrong: “What is actually running?” is always the first debugging question.
  • Portable: ps works the same on virtually every Unix-like system, even where top behaves differently.
  • Scriptable: Its output is plain text, perfect for piping into grep or awk.
  • It teaches you the PID: Every other process tool — kill, pkill, renice — works from the process IDs ps reveals.

ps is a photograph, not a video. If you need to watch a process change over time, use top or htop instead.


1. The Classic ps aux

ps aux
  • a — show processes for all users.
  • u — show output in user-oriented format (who owns it, CPU%, memory%).
  • x — include processes not attached to a terminal (daemons and background services).

The output columns are:

ColumnMeaning
USERWho started the process.
PIDProcess ID — the number every other tool uses.
%CPUShare of CPU used (an average since start, not instantaneous).
%MEMShare of physical memory in use.
VSZVirtual memory size, in KB.
RSSReal (physical) memory size, in KB.
TTYWhich terminal it is attached to (? means none).
STATProcess state (R running, S sleeping, Z zombie, …).
STARTWhen it started.
TIMETotal CPU time consumed.
COMMANDThe command line that started it.

To find a specific process in a long list, pipe it:

ps aux | grep firefox

2. The Modern ps Format

The BSD-style options (aux) are historic. Modern ps uses its own flag names, which are easier to remember:

ps -ef
  • -e — every process.
  • -f — full-format listing (adds PPID, start time, and the full command).
ps axjf
  • j — adds job control info (session and parent process IDs), which makes it easy to see which shell started which program.

3. Show Only Your Own Processes

ps

With no options, ps lists only the processes attached to your current terminal. That is often enough to find the program you just launched:

ps -l
  • -l — the long “linux format”, showing UID, PPID, nice value, and state flags.

4. Find a Process by Name

Combine ps with grep:

ps aux | grep nginx

That shows any running nginx processes. A common refinement:

ps aux | grep [n]ginx

The bracket trick stops grep from matching its own command line in the output. When a process is not there, that line disappears — which is itself useful information.


5. Watch a Process Change

ps -p 1234 -o pid,pcpu,pmem,cmd
  • -p 1234 — restrict to PID 1234.
  • -o ... — choose exactly the columns you want.

Re-running this every few seconds (or wrapping it in watch later in this book) is a lightweight way to poll a single process without launching a full top session.


Common Pitfalls

  • ps aux vs ps -ef is not the same list. ps aux can miss processes without a controlling terminal on some systems; ps -ef can miss session details. When in doubt, use ps aux for a general scan or ps -ef for parent-child relationships.
  • %CPU in ps is an average since the process started, not what it is using this second. A process can show 0% here and still be busy right now — that is top’s job.
  • The COMMAND column is truncated in the default format. Use ps -ef or ps auxww for the full command line.
  • grep matches itself (ps aux | grep foo also lists the grep process). Use the bracket trick [f]oo or switch to pgrep.
  • Zombie processes (Z state) are not really running. They are dead entries waiting for their parent to read their exit status; you cannot kill them directly — see kill.

PageRelationship
topLive, updating view of processes instead of a snapshot.
htopColorful interactive alternative to top.
pgrepFind process IDs by name without parsing ps output.
killSend signals to the PIDs ps reveals.
jobsThe shell’s own list of background jobs.

ps Cheatsheet

CommandWhat It Does
ps auxAll processes, user-friendly format.
ps -efEvery process, full-format listing.
ps axjfProcess tree with job-control info.
psProcesses attached to your terminal.
ps aux | grep [n]ginxFind processes matching a name.
ps -p 1234 -o pid,pcpu,cmdChosen columns for one PID.
ps aux --sort=-%mem | headTop memory consumers.
ps auxwwFull command lines, not truncated.