Viewing Processes: ps & top

ps takes a snapshot of running processes; top and htop show them updating live.

Syntaxps aux top # or htop

Every running program is a process with a unique PID (process ID). Two tools let you see them.

ps — a snapshot

ps aux lists every process on the system with its user, PID, CPU and memory use. It prints once and exits, so it pairs naturally with grep.

top / htop — a live view

top refreshes continuously, showing the busiest processes and overall CPU and memory load. Press q to quit. htop is a friendlier, colourful version you can install — it lets you scroll and kill processes with the arrow keys.

Example

Example · bash
# Every process, one snapshot
ps aux
# USER  PID %CPU %MEM COMMAND
# alice 981  2.1  0.5 /usr/bin/node server.js

# Is nginx running? Find its PID
ps aux | grep nginx

# Live, updating view
top

When to use it

  • A sysadmin runs 'ps aux --sort=-%cpu | head -10' to identify which processes are consuming the most CPU during a performance incident.
  • A developer uses 'top -u alice' to monitor only their own processes while profiling a long-running data pipeline.
  • A DevOps engineer runs 'ps -eo pid,comm,rss --sort=-rss | head -10' to find the highest memory consumers before an OOM event.

More examples

List all running processes

Shows ps aux, the most common invocation, with column meanings: PID, CPU/MEM%, VSZ/RSS memory, and command.

Example · bash
# a = all users, u = user-friendly, x = include no-tty
ps aux | head -5
# USER       PID %CPU %MEM   VSZ  RSS STAT  COMMAND
# root         1  0.0  0.1 22544 9152 Ss    /sbin/init

Find a specific process

Uses ps+grep and the cleaner pgrep to locate a process by name and retrieve its PID.

Example · bash
# Find nginx processes
ps aux | grep nginx | grep -v grep

# Or use pgrep for just the PID
pgrep -la nginx
# 1234 nginx: master process
# 1235 nginx: worker process

Monitor processes interactively with top

Opens top for live monitoring and lists the key commands; -bn1 captures a one-shot snapshot for scripting.

Example · bash
# Launch top, then:
top
# Keys while running:
# M  - sort by memory
# P  - sort by CPU (default)
# k  - kill a process by PID
# q  - quit

# Non-interactive snapshot (1 iteration)
top -bn1 | head -20

Discussion

  • Be the first to comment on this lesson.