Linux interview question · Most asked
What do top, htop, vmstat, iostat, ss and lsof each tell you?
Definition Asked in DevOps Engineer · Site Reliability Engineer (SRE) interviews
Summary
top/htop show live per-process CPU and memory; vmstat shows system-wide CPU, memory, swap and run queue over
time; iostat -x shows per-disk throughput, latency and utilisation; ss lists sockets and connection states;
lsof lists open files, including sockets, per process.
Longer Answer
| Tool | Use it for | Look at |
|---|---|---|
top / htop |
Which process uses CPU or memory | %CPU, RES, load average, us/sy/wa/st |
vmstat 1 |
Whole-system trend | r (run queue), si/so (swapping), wa |
iostat -x 1 |
Disk bottlenecks | await (latency), %util, r/s and w/s |
ss -tulpn / ss -s |
Listening ports, connection counts | LISTEN, ESTAB, TIME_WAIT, owning process |
lsof -p PID / lsof -i :443 |
Files and sockets a process holds | deleted-but-open files, too many fds |
netstat |
Older equivalent of ss |
replaced by ss on modern systems |
Together they answer "is it CPU, memory, disk or network?" quickly; that's Brendan Gregg's USE method (utilisation, saturation, errors) applied with standard tools.
Key Points
- top/htop: per process.
- vmstat: system-wide trend and run queue.
- iostat -x: disk latency and utilisation.
- ss: sockets and states; lsof: open files per process.
Explanation
What interviewers look for
Knowing which tool answers which question, and the key column in each.
More Linux questions
- A Linux server has high CPU usage. How do you find the cause?
- Write a script that alerts when disk usage passes a threshold.
- How do you troubleshoot DNS resolution and network connectivity on Linux?
- A server keeps running out of memory and the kernel kills processes. How do you investigate?
- The disk is full, but du shows far less usage than df. What's going on?
- How do systemd units work, and how do you debug a service that won't start?
- Explain Linux file permissions, ownership and the special bits.
- What is load average, and how is it different from CPU utilisation?