C.W.K.
Stream
Lesson 01 of 10 · published

ps: Listing Processes

~10 min · ps, process

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

What's running right now?

ps snapshots the process table. There are two flag dialects — BSD (no dash, like ps aux) and SysV (dashes, like ps -ef). On macOS both work; pick the form that's clearer to you and stick with it.

The combos you'll wear out

  • ps aux — every process, all users, full command line. The default ps view.
  • ps -ef — same idea, SysV style.
  • ps -p <pid> — info about one PID.
  • ps aux | grep -i firefox | grep -v grep — find by name. The -v grep hides grep itself.
  • ps -o pid,ppid,command — pick exactly the columns you want.

The columns you'll care about

  • USER — process owner.
  • PID — the unique number you'll kill.
  • %CPU, %MEM — instantaneous load.
  • RSS — resident memory in KB.
  • STAT — state (R running, S sleep, Z zombie, T stopped, ...).
  • COMMAND — the executable + args. Truncated unless you expand the column.

Pgrep / pkill — find or kill by name

pgrep firefox prints the PIDs. pkill -f 'python myscript' kills every process whose full command matches. Way cleaner than the grep dance.

Code

Find a runaway process·bash
ps aux | sort -nrk 3 | head -10           # top 10 by CPU
ps aux | sort -nrk 4 | head -10           # top 10 by MEM
pgrep -fa python                          # PID + full cmd

External links

Exercise

Run ps aux | sort -nrk 3 | head -5 — your top 5 CPU consumers. Find your shell's PID: pgrep -fa zsh. Get just your processes: ps -u $(whoami) -o pid,%cpu,command | head.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.