Quick take: The top command shows a live, updating view of processes and system load; htop is a friendlier, colourful alternative with mouse support. Inside top, press M to sort by memory, P by CPU, and k to kill a process.
Introduction
When a server is slow, top and htop tell you why. They display a live view of running processes alongside CPU usage, memory consumption, and the system load average, refreshing every couple of seconds. htop adds colour, scrolling, and mouse support, but is not always installed by default.
This guide covers reading the summary metrics, sorting and filtering processes, and acting on them without leaving the monitor.
Syntax
The basic syntax of the top and htop command is:
top [OPTIONS]
htop [OPTIONS]Common Options and Parameters
The most useful options and parameters for the top and htop command:
| Option | Description |
|---|---|
| M (in top) | Sort processes by memory usage. |
| P (in top) | Sort processes by CPU usage. |
| k (in top) | Kill a process by entering its PID. |
| q (in top) | Quit the monitor. |
| -u USER | Show only processes owned by a user. |
| -p PID | Monitor specific process IDs. |
| -d SECS | Set the refresh delay. |
| -b | Batch mode (non-interactive, for logging to a file). |
| F2 / F3 / F9 (htop) | Configure, search, and kill within htop. |
Practical Examples
Real top and htop commands you can run today:
# Launch the live process monitor
top
# Launch the friendlier htop
htop
# Install htop on Ubuntu/Debian
sudo apt install htop
# Show only one user's processes
top -u www-data
# Monitor specific PIDs
top -p 1234,5678
# Capture one snapshot to a file (batch mode)
top -b -n 1 > top-snapshot.txtReading the System Summary
The header at the top of top and htop is where the real diagnosis happens. The load average shows the average number of processes wanting CPU over 1, 5, and 15 minutes — compare it to your core count, since a load of 4.0 on a 4-core machine means it is fully busy but not necessarily overloaded.
The CPU line breaks usage into us (user programs), sy (kernel), wa (waiting on disk I/O), and id (idle). A high wa points to a disk bottleneck rather than a CPU one. The memory lines distinguish used, free, and buff/cache — Linux deliberately uses spare RAM for caching, so low “free” is normal and not a problem on its own.
Tips and Best Practices
- In
top, the load average shows demand over 1, 5, and 15 minutes — compare it to your CPU core count to judge whether the system is overloaded. - Press
MthenPin top to flip between memory and CPU sorting while hunting a resource hog. - Use
htopwhen available — F6 to sort, F9 to kill, and F3 to search are far easier than top's key bindings.
Final Thoughts
top and htop are the first commands to run when a system feels slow, giving a live picture of CPU, memory, load, and the processes responsible. Learn to sort by CPU and memory and to read the load average, and you can pinpoint a runaway process in seconds — then stop it with kill or right inside the monitor.
FAQ: top and htop Command in Linux
How do I monitor CPU and memory usage in Linux?+
Run top for a built-in live monitor, or htop for a friendlier coloured version. Both show per-process CPU and memory plus a system summary at the top.
How do I sort processes by memory in top?+
Press M while top is running to sort by memory usage, or P to sort by CPU. Press q to quit.
How do I install htop?+
On Ubuntu or Debian run sudo apt install htop; on RHEL or Fedora use sudo dnf install htop. Then launch it by typing htop.
What does the load average mean in top?+
The three numbers are the average number of processes wanting CPU over the last 1, 5, and 15 minutes. Compare them to your core count — a load near the number of cores means the CPU is fully used.
How do I kill a process from top?+
Press k, type the PID, and confirm the signal. In htop, highlight the process and press F9 to send a signal.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support