top and htop
ps shows a snapshot. top and htop show live, updating views of your system.
top - The Classic
You'll see a dashboard that updates every few seconds.
Understanding top's Display
Header Section
top - 10:30:45 up 5 days, 3:22, 2 users, load average: 0.15, 0.10, 0.09
Tasks: 142 total, 1 running, 141 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.3 us, 1.0 sy, 0.0 ni, 96.5 id, 0.2 wa, 0.0 hi, 0.0 si
MiB Mem : 7976.5 total, 3245.2 free, 2134.8 used, 2596.5 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 5432.1 avail Mem
Key metrics:
- Load average: CPU demand over 1, 5, 15 minutes
- Tasks: Process count by state
- %Cpu: CPU time breakdown
- Mem/Swap: Memory usage
Load Average
A load of 1.0 means 100% CPU capacity (on single core). With 4 cores, 4.0 is 100%. Below the core count = healthy.
Process List
| Column | Meaning |
|---|---|
| PID | Process ID |
| USER | Owner |
| PR | Priority |
| NI | Nice value |
| VIRT | Virtual memory |
| RES | Resident (physical) memory |
| SHR | Shared memory |
| S | Status |
| %CPU | CPU percentage |
| %MEM | Memory percentage |
| TIME+ | Total CPU time |
| COMMAND | Command name |
top Keyboard Commands
While in top:
| Key | Action |
|---|---|
q | Quit |
h | Help |
k | Kill a process (enter PID) |
r | Renice (change priority) |
M | Sort by memory |
P | Sort by CPU |
u | Filter by user |
1 | Show individual CPU cores |
c | Show full command path |
htop - The Better top
htop is top with a better interface:
Install htop
htop isn't always pre-installed:
sudo apt install htop # Debian/Ubuntu
sudo yum install htop # RHEL/CentOS
htop Advantages
- Color-coded - easier to read
- Mouse support - click to select/sort
- Horizontal scrolling - see long commands
- Tree view - built in (F5)
- Search - F3 to search processes
- Kill - F9 for kill menu
htop Keyboard
| Key | Action |
|---|---|
F1 | Help |
F2 | Setup |
F3 | Search |
F4 | Filter |
F5 | Tree view |
F6 | Sort by |
F9 | Kill |
F10 | Quit |
\ | Filter by command |
/ | Search |
Reading CPU/Memory Bars
In htop, the colored bars show:
CPU bars:
- Blue: Low priority
- Green: Normal user processes
- Red: Kernel processes
- Cyan: Virtualization
Memory bars:
- Green: Used memory
- Blue: Buffers
- Orange: Cache
When to Use Which
| Tool | Best For |
|---|---|
ps aux | Quick snapshot, scripting |
top | Live monitoring, any system |
htop | Interactive investigation, kills |
In top/htop, what does a load average of 4.0 on a 4-core system indicate?
Key Takeaways
topis the classic real-time process viewerhtopis a friendlier, more powerful alternative- Load average shows CPU demand (compare to core count)
- Use keyboard shortcuts for sorting and killing
- F9 in htop gives a convenient kill menu
Next: managing foreground and background processes.