When a VPS feels slow, top and htop show which processes use the CPU and memory right now. top is always installed; htop is friendlier, with colours, mouse support and easy sorting.
Before you start
- SSH access (see connect with SSH).
- Install htop:
sudo apt install htoporsudo dnf install epel-release htop.
Read the header
- Load average (1, 5, 15 minutes): processes waiting for CPU. Compare with your core count (
nproc): a load of 4 on 4 cores is fully busy. - CPU %:
ususer apps,sykernel,wawaiting for disk (high means slow storage or heavy I/O),ststeal time taken by the host. - Memory: Linux uses spare RAM as cache, so look at available, not free.
- Swap: steady swap use with low available RAM means you need more memory (see add a swap file).
Use top
top| Key | Action |
|---|---|
P / M | Sort by CPU / memory |
1 | Show each CPU core |
u | Filter by user |
c | Show full command lines |
k | Kill a process by PID |
q | Quit |
Use htop
htopClick a column header (or press F6) to sort, F3 to search, F4 to filter, F5 for a tree view showing parent and child processes, F9 to send a signal, and F10 to quit.
Stop a runaway process
Prefer restarting the owning service (sudo systemctl restart php-fpm, see systemctl). For a stray process:
kill 12345
kill -9 12345Plain kill asks it to exit cleanly; -9 forces it and can lose unsaved data.
One-shot snapshots
ps aux --sort=-%cpu | head -n 10
ps aux --sort=-%mem | head -n 10
free -hTroubleshooting
- High wa: disk-bound; check with
iotopand look for backups or large queries. - High st: the host is busy; if it persists, contact support with timestamps.
- Processes killed unexpectedly: the out-of-memory killer acted; check
journalctl -k | grep -i oom.
