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 htopDoes
F6 or < >Sort by column (CPU%, MEM%…)
P / M / TSort by CPU / memory / time
F5 or tTree view: which process started which
F4 or \Filter by name
uShow only one user’s processes
F9 or kKill the selected process
F10 or qQuit

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

Quick commands

QuestionCommand
Memory overviewfree -h (look at available)
Top 10 processes by memoryps aux --sort=-%mem | head -11
Top 10 processes by CPUps aux --sort=-%cpu | head -11
Usage per service (live)systemd-cgtop
Memory and CPU of one servicesystemctl status nginx (shows Memory: and CPU:)
Which process uses disk I/O?sudo iotop -o (sudo apt install iotop)
Disk I/O per deviceiostat -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 loaduptime
Find a process by namepgrep -a nginx
Kill a processkill PID, if it won’t die: kill -9 PID
Kill by namepkill -f myscript.sh
Was something killed for lack of RAM?journalctl -k -g "Out of memory"

Typical findings

§ home
~/knubertus/home/
1,1 Top