ubuntu, updated
Task manager: who uses CPU, RAM, disk?
The Linux task manager: top and htop, plus quick commands to see which process or service uses CPU, memory, disk I/O and network.
The task manager: top and htop
top is always there. htop is friendlier (colors, mouse, tree view) and is installed on Ubuntu Server by default (sudo apt install htop if not).
htop
| Key in htop | Does |
|---|---|
F6 or < > | Sort by column (CPU%, MEM%…) |
P / M / T | Sort by CPU / memory / time |
F5 or t | Tree view: which process started which |
F4 or \ | Filter by name |
u | Show only one user’s processes |
F9 or k | Kill the selected process |
F10 or q | Quit |
In plain top: P sort by CPU, M by memory, 1 show each CPU core, k kill, q quit.
Reading the header
load average: 0.52, 0.71, 0.80
MiB Mem : 7940.3 total, 412.6 free, 2210.4 used, 5317.3 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 5420.1 avail Mem
- Load average = processes running or waiting, over 1, 5 and 15 minutes. Compare with the number of cores (
nproc). Load 4 on 4 cores = busy but fine; load 12 on 4 cores = overloaded. - Memory: low free is normal. Linux uses spare RAM as cache. What matters is avail Mem. If that is low and swap is in use, you are short of RAM.
Quick commands
| Question | Command |
|---|---|
| Memory overview | free -h (look at available) |
| Top 10 processes by memory | ps aux --sort=-%mem | head -11 |
| Top 10 processes by CPU | ps aux --sort=-%cpu | head -11 |
| Usage per service (live) | systemd-cgtop |
| Memory and CPU of one service | systemctl status nginx (shows Memory: and CPU:) |
| Which process uses disk I/O? | sudo iotop -o (sudo apt install iotop) |
| Disk I/O per device | iostat -x 2 (sudo apt install sysstat) |
| Which process uses the network? | sudo nethogs (sudo apt install nethogs) |
| Which process listens on which port? | sudo ss -tulpn |
| Uptime and load | uptime |
| Find a process by name | pgrep -a nginx |
| Kill a process | kill PID, if it won’t die: kill -9 PID |
| Kill by name | pkill -f myscript.sh |
| Was something killed for lack of RAM? | journalctl -k -g "Out of memory" |
Typical findings
- High CPU from one process: check its log, restart the service. Recurring at the same time? Look at cronjobs and
systemctl list-timers. - High load but low CPU: processes are waiting for disk or network. Check
iotopandiostat. - Memory slowly growing: possible memory leak in an app. Limit it with
MemoryMax=1Gin a service override. - Disk full: see List disks and volumes.