Checking CPU usage on Linux has four tools that answer different questions: top for a live overview, htop for a better interactive view, mpstat -P ALL for per-CPU breakdown, and /proc/stat for raw numbers. The team that reaches for the right tool based on the question (who is using CPU? which core? what’s the average over time?) finds the answer in seconds.
Table of contents
- top: the live overview
- htop: the better interactive view
- mpstat: per-CPU breakdown
- Raw numbers from /proc/stat
- Other useful tools
- FAQ
top: the live overview
top
top shows processes sorted by CPU usage, plus the system-wide CPU line at the top. Key fields:
%Cpu(s):line shows user, system, idle, iowait, steal, etc.PID,USER,%CPU,%MEM,COMMANDper process.
Interactive shortcuts: P (sort by CPU), M (sort by memory), 1 (toggle per-CPU view), k (kill a process), q (quit).
The team that has top on muscle memory gets the answer in 5 seconds. The team that wants a better UI uses htop.
htop: the better interactive view
htop
htop (install via apt install htop or yum install htop) shows the same data as top but with color, mouse support, and per-CPU bars by default. The team that has htop installed never goes back to top for interactive use.
mpstat: per-CPU breakdown
mpstat -P ALL 1
mpstat (from the sysstat package) shows per-CPU statistics refreshed every second. The output looks like:
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
all 12.5 0.0 2.1 5.3 0.0 0.3 0.0 0.0 79.8
0 8.2 0.0 1.9 4.7 0.0 0.2 0.0 0.0 85.0
1 16.8 0.0 2.3 5.9 0.0 0.4 0.0 0.0 74.6
The team that has a single-threaded bottleneck sees one core at 100% and the others idle. That pattern is the smoking gun for non-thread-safe code.
Raw numbers from /proc/stat
cat /proc/stat | head -5
The first line (cpu) has the system-wide totals: user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice. The cpu0, cpu1, etc. lines have per-CPU breakdowns.
Tools like sar, collectd, and Prometheus node_exporter parse this file. The team that uses these for time-series monitoring gets the historical view that top cannot show.
Other useful tools
vmstat 1- virtual memory stats (CPU + memory + IO together).pidstat -p <pid> 1- per-process CPU and IO stats.perf top- call-graph profiling (find the function using CPU).turbostat- CPU frequency and C-state stats (Intel CPUs).
The team that has a specific question uses the right tool. The team that always reaches for top first is missing out on the more specific answers.
FAQ
What does %CPU mean in top?
The percentage of a single CPU core that the process is using. A multi-threaded process can show >100% (e.g., 200% on a 4-core box if it’s using 2 cores fully). The team that sees 800% on an 8-core box is looking at a fully parallel workload.
How do I see CPU usage over time?
Use sar -u 1 60 (from sysstat) to sample every second for 60 seconds. The team that uses collectd, Prometheus, or a hosted monitoring tool gets longer historical views.
Why is iowait high?
The CPU is waiting for IO (disk, network). High iowait with low user/system CPU usually means the disk is the bottleneck, not the CPU. The team that sees this should check iostat -x 1 for per-disk latency.
What is steal time?
The percentage of CPU time the hypervisor gave to other VMs. High steal time means the cloud host is oversubscribed - the team that sees >10% steal time should consider a different instance type or a less crowded cloud region.
Can I check CPU usage from /proc without top?
Yes. cat /proc/stat has the raw numbers; ps -eo pid,user,pcpu,comm --sort=-pcpu | head shows top processes. The team that uses ps in scripts and top interactively has the right split.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: