Skip to main content

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.

Quick Summary

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

top-screen-mental-model.txt
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-version.sh
top -V

Core Syntax

top-syntax.sh
top [OPTIONS]

Key Options

OptionWhat it doesExampleWordPress / VPS use case
-b -n 1Batch mode + one iterationtop -b -n 1Paste a snapshot into incident notes
-o <FIELD>Sort by a fieldtop -o %MEMStart sorted by memory
-p <PIDLIST>Monitor specific PID(s)top -p 1234Watch a single php-fpm or mysqld process
-u <USER>Show only a usertop -u www-dataFocus on web server/PHP processes
-HShow threadstop -HDebug multi-threaded services
-d <secs>Refresh delaytop -d 2Reduce terminal noise

Examples (Commands + Expected Output)

Output varies

Process names depend on your stack (nginx/apache, php-fpm, litespeed, mariadb).

Run top interactively

top-interactive.sh
top

Expected output (excerpt):

example-output-top-excerpt.txt
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-batch-one-snapshot.sh
top -b -n 1

Expected output (excerpt):

example-output-top-batch-excerpt.txt
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-sort-by-memory.sh
top -o %MEM

Expected output:

example-output-top-sort-memory.txt
... (process list sorted by %MEM)

Use case: Find memory hogs that trigger swapping/OOM kills.

Monitor only a specific PID

top-monitor-specific-pid.sh
top -p 12345

Expected output:

example-output-top-pid.txt
... (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-filter-by-user.sh
top -u www-data

Expected output:

example-output-top-user.txt
... (shows processes owned by www-data)

Use case: Focus on WordPress/PHP activity.

Show threads

top-show-threads.sh
top -H

Expected output:

example-output-top-threads.txt
... (threads included)

Use case: Debug multi-threaded workloads.

WordPress VPS Use Cases

SymptomWhat to look forCommand / keyNext step
Slow siteHigh %CPU on php-fpmtop + PCheck slow logs / caching
502/504 spikesSwapping and high %MEMtop + MCheck free -h and reduce memory usage
High load averageHigh watop headerConfirm with iostat / vmstat
Backup window issuesrsync/tar CPU spikestop -o %CPUSchedule backups off-peak

Troubleshooting

ObservationLikely causeWhat to do
High load but CPU idleI/O wait or runnable queueCheck wa and confirm with iostat / vmstat
Swap used risingMemory pressureCheck free -h and reduce memory usage
Many php-fpm workersTraffic spike or slow backendCheck DB, caching, and slow queries

Best Practices

  • Use batch mode (-b -n 1) when you need repeatable output.
  • Pair top with free and vmstat to confirm whether the bottleneck is CPU, memory, or disk.
Interactive Keys Cheat Sheet
top-interactive-keys.txt
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

What's Next