htop and top provide real-time visibility into CPU, memory, and process activity — the first tools to reach for when diagnosing a server that feels slow or unresponsive.
top: The Built-In Standard
top
Shows a live-updating view of CPU/memory usage and running processes, sorted by CPU usage by default — available on virtually every Linux system with no installation needed.
Key top Interactive Commands
P # sort by CPU usage
M # sort by memory usage
k # kill a process (prompts for PID)
q # quit
htop: A More User-Friendly Alternative
sudo apt install htop -y
htop
Adds color-coded output, mouse support, and easier process searching/killing compared to top's more austere interface.
Understanding the Key Metrics
| Metric | Meaning |
|---|---|
| Load average | Average system load over 1/5/15 minutes; compare against your CPU core count |
| %CPU | Percentage of a single CPU core a process is using |
| RES (Resident Memory) | Actual physical RAM a process is currently using |
| VIRT (Virtual Memory) | Total virtual memory a process has mapped, often much higher than actual usage |
Interpreting Load Average
A load average roughly equal to your CPU core count indicates full utilization; significantly higher indicates processes are waiting for CPU time — e.g. a load average of 8 on a 4-core server suggests the system is meaningfully oversubscribed.
Filtering/Searching for a Specific Process in htop
F4 # filter by process name
Killing a Runaway Process
# In htop: select the process, press F9, choose signal (15 for graceful, 9 for force)
# Or from the command line:
kill -15 PID
kill -9 PID # force kill if graceful termination doesn't work
Always try a graceful termination (-15) first, reserving force kill (-9) for processes that don't respond to the graceful signal.
Viewing Per-Core CPU Usage in htop
htop's header displays individual core utilization bars — useful for spotting whether load is evenly distributed or concentrated on a single core (which can indicate a single-threaded process bottleneck).
Sorting by Memory to Find Memory Leaks
htop
M # sort by memory usage
A process whose memory usage climbs steadily over time without leveling off is a classic sign of a memory leak worth investigating.
Command-Line Alternative for Scripting: ps
ps aux --sort=-%cpu | head -10
Useful when you need a one-time snapshot for a script or report, rather than htop/top's interactive live view.
Common Errors
High load average but low CPU usage per process — check for processes in "D" state (uninterruptible sleep, often waiting on disk I/O) rather than assuming it's purely a CPU issue.
Continue Reading
- How to Find and Stop Processes Using Too Many Resources
- How to Check VPS Resource Usage (CPU, RAM & Disk)
- How to Set Up Prometheus and Grafana for VPS Monitoring
Browse more articles in Linux Server Administration.