top — Real-Time Process Monitoring
top provides a live view of system load and processes (CPU, memory, and process-level usage). Use it when WordPress is slow, when you suspect a runaway PHP process, or when you want to see whether MySQL/MariaDB is consuming CPU or RAM. For one-off snapshots (like in tickets), use batch mode.
Run top, then press P (sort by CPU) or M (sort by memory). For a single snapshot you can paste into a ticket: top -b -n 1.
What You're Looking At
Header: uptime + load average + CPU breakdown + memory/swap
List: processes sorted by CPU/memory
Keys: P/M/T to sort, 1 per-CPU, c command line, q quit
Prerequisites
top is part of procps/procps-ng and is installed by default on most Linux servers.
Verify version:
top -V
Core Syntax
top [OPTIONS]
Key Options
| Option | What it does | Example | WordPress / VPS use case |
|---|---|---|---|
-b -n 1 | Batch mode + one iteration | top -b -n 1 | Paste a snapshot into incident notes |
-o <FIELD> | Sort by a field | top -o %MEM | Start sorted by memory |
-p <PIDLIST> | Monitor specific PID(s) | top -p 1234 | Watch a single php-fpm or mysqld process |
-u <USER> | Show only a user | top -u www-data | Focus on web server/PHP processes |
-H | Show threads | top -H | Debug multi-threaded services |
-d <secs> | Refresh delay | top -d 2 | Reduce terminal noise |
Examples (Commands + Expected Output)
Process names depend on your stack (nginx/apache, php-fpm, litespeed, mariadb).
Run top interactively
top
Expected output (excerpt):
top - 10:10:10 up 12 days, 3:01, 1 user, load average: 0.32, 0.28, 0.20
Tasks: 145 total, 1 running, 144 sleeping, 0 stopped, 0 zombie
%Cpu(s): 6.0 us, 2.0 sy, 0.0 ni, 90.0 id, 2.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 2048.0 total, 120.0 free, 700.0 used, 1228.0 buff/cache
MiB Swap: 1024.0 total, 1000.0 free, 24.0 used
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12345 www-data 20 0 450000 120000 20000 R 80.0 5.9 0:30.12 php-fpm
2345 mysql 20 0 1200000 300000 40000 S 20.0 14.6 5:12.44 mariadbd
Use case: Identify whether CPU (%CPU) or I/O wait (wa) is the bottleneck.
One snapshot in batch mode
top -b -n 1
Expected output (excerpt):
top - 10:10:10 up 12 days, 3:01, 1 user, load average: 0.32, 0.28, 0.20
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12345 www-data 20 0 450000 120000 20000 R 80.0 5.9 0:30.12 php-fpm
Use case: Capture the current state for troubleshooting.
Start sorted by memory
top -o %MEM
Expected output:
... (process list sorted by %MEM)
Use case: Find memory hogs that trigger swapping/OOM kills.
Monitor only a specific PID
top -p 12345
Expected output:
... (shows only the selected PID)
Use case: Watch a long-running backup job, a php-fpm worker, or a DB process.
Filter by user (web server / PHP)
top -u www-data
Expected output:
... (shows processes owned by www-data)
Use case: Focus on WordPress/PHP activity.
Show threads
top -H
Expected output:
... (threads included)
Use case: Debug multi-threaded workloads.
WordPress VPS Use Cases
| Symptom | What to look for | Command / key | Next step |
|---|---|---|---|
| Slow site | High %CPU on php-fpm | top + P | Check slow logs / caching |
| 502/504 spikes | Swapping and high %MEM | top + M | Check free -h and reduce memory usage |
| High load average | High wa | top header | Confirm with iostat / vmstat |
| Backup window issues | rsync/tar CPU spikes | top -o %CPU | Schedule backups off-peak |
Troubleshooting
| Observation | Likely cause | What to do |
|---|---|---|
| High load but CPU idle | I/O wait or runnable queue | Check wa and confirm with iostat / vmstat |
| Swap used rising | Memory pressure | Check free -h and reduce memory usage |
| Many php-fpm workers | Traffic spike or slow backend | Check DB, caching, and slow queries |
Best Practices
- Use batch mode (
-b -n 1) when you need repeatable output. - Pair
topwithfreeandvmstatto confirm whether the bottleneck is CPU, memory, or disk.
Interactive Keys Cheat Sheet
P sort by CPU
M sort by memory
T sort by time
1 toggle per-CPU view
c toggle full command line
k kill a process (prompts for PID)
r renice a process
q quit