How to Check CPU Usage in Linux: mpstat, top, vmstat & /proc/stat
Learn check cpu usage in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
12 min read
Learn check cpu usage in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What mpstat Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
Diagnosing latency spikes, runaway processes, storage bottlenecks, or noisy-neighbor throttling on cloud virtual machines requires knowing how to check cpu usage in linux beyond a single aggregate percentage. Modern multi-socket servers and cloud instances schedule threads across dozens of logical vCPUs, meaning a single-threaded process pegged at 100% on CPU 0 can bottleneck an application while overall system utilization across 32 cores appears to sit at a calm 3%.
To check CPU usage in Linux accurately across all processor cores, run mpstat -P ALL 1 5 from the sysstat package, or use top / htop for interactive per-process monitoring and vmstat 1 for system-wide scheduling telemetry. These utilities read kernel tick counters from /proc/stat to break CPU time down into user (%usr), kernel (%sys), I/O wait (%iowait), hardware/software interrupts (%irq, %soft), hypervisor steal (%steal), and idle (%idle) percentages.
Linux provides a layered toolkit for processor telemetry: mpstat (from the sysstat suite) measures per-core and aggregate CPU state distributions; pidstat and top isolate specific processes and threads consuming cycles; vmstat correlates CPU saturation with run-queue depth and context switches; and /proc/stat exposes the raw kernel jiffy counters directly for zero-dependency scripts.
In this guide, we focus on mpstat alongside complementary Linux CPU diagnostic utilities, explain what each kernel CPU state (%usr, %sys, %iowait, %steal, %soft) reveals about your workload, and demonstrate practical commands and alerting pipelines.
/proc/stat — command syntax, key options, and production workflow reference.What mpstat Does and When to Use It
Every CPU monitoring tool on Linux ultimately derives its metrics from /proc/stat, a pseudo-file maintained by the kernel scheduler. For each logical processor, the kernel increments monotonic counters measured in USER_HZ clock ticks (traditionally 100 ticks/jiffies per second) across ten scheduling states: user, nice, system, idle, iowait, irq, softirq, steal, guest, and guest_nice. Because /proc/stat stores cumulative ticks since boot, calculating live CPU utilization requires taking two snapshots separated by a sampling interval (such as 1 second) and computing the delta of each state divided by total elapsed ticks.
Understanding the distinction between CPU utilization and Linux Load Average (/proc/loadavg or uptime) is equally critical. On Linux, Load Average counts not only runnable threads actively executing or waiting on a CPU run-queue (R state), but also threads stuck in uninterruptible sleep (D state) waiting on disk or NFS I/O. Consequently, a server with deadlocked storage can exhibit a Load Average of 50.0 while actual CPU execution (%usr + %sys) is nearly 0% and %iowait is elevated.
Under the hood, mpstat gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as -P, -u, -I, -N turns raw process and service tables into actionable diagnostics during incident response.
Availability and Installation Across Linux Distributions
The mpstat utility is packaged in sysstat across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether mpstat is installed and inspect which binary path and version your shell resolves:
type -a mpstat
mpstat --version 2>/dev/null || man -f mpstat
# Illustrative output (reviewed against documentation)
mpstat is /usr/bin/mpstat
mpstat (sysstat)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y sysstat
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y sysstat
# Arch Linux
sudo pacman -S --noconfirm sysstat
# Alpine Linux
sudo apk add --no-cache sysstat
Command Syntax, Arguments, and Exit Status Codes
mpstat [ -P { cpu_list | ALL } ] [ -u ] [ -o JSON ] [ interval [ count ] ]
When invoking mpstat [OPTIONS] [INTERVAL [COUNT]], omitting both INTERVAL and COUNT prints a single line representing the average CPU utilization since the system booted—a common pitfall similar to running iostat or vmstat without an interval. Always pass an explicit sampling interval in seconds (for example, mpstat 1 5 to take five 1-second samples) so you measure current real-time processor activity.
To inspect individual logical cores rather than a single system-wide average row, pass -P ALL or a comma/range list such as -P 0,1,4-7. You can also combine mpstat with -o JSON to emit structured telemetry for log shippers and monitoring agents.
0— Telemetry sampling completed for the requested interval and count without error.1— Invalid command-line option, invalid CPU range specification, or syntax error.2— Unable to read kernel statistics from/proc/stator interrupt table files.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
-P | -P { cpu_list | ALL } | Displays utilization metrics for specific logical CPU IDs (e.g., 0,2-3), online CPUs (ON), or every logical core (ALL). |
-u | -u | Reports standard CPU utilization breakdown (%usr, %nice, %sys, %iowait, %irq, %soft, %steal, %guest, %idle); enabled by default. |
-I | -I { SUM | CPU | SCPU | ALL } | Reports hardware and software interrupt rates per second across CPUs to diagnose network or storage IRQ storms. |
-N | -N { node_list | ALL } | Aggregates CPU utilization metrics by NUMA (Non-Uniform Memory Access) placement nodes on multi-socket hardware. |
-o | -o JSON | Formats all sampled CPU and interrupt statistics as valid JSON for automated ingestion by jq or observability agents. |
-dec | --dec={ 0 | 1 | 2 } | Specifies the number of decimal places (0 to 2, default 2) used when printing percentage metrics. |
-T | -T | Includes physical core and socket topology identifiers alongside logical CPU numbers to distinguish hyperthreads. |
-V | -V | Prints the installed sysstat version number and exits. |
Interpreting the columns returned by mpstat -P ALL tells you immediately where a performance bottleneck originates. High %usr or %nice indicates userspace application computation (such as JSON serialization, compression, or cryptographic hashing). High %sys points to excessive kernel syscall overhead or lock contention. High %soft frequently indicates network packet processing saturation (ksoftirqd/N) on a single core handling NIC receive queues.
On virtualized cloud instances (AWS EC2, GCP, Azure, KVM), always watch the %steal column: if %steal exceeds 5–10%, the physical hypervisor host is oversubscribed or throttling your VM's CPU burst credits, meaning your instance is ready to run code but waiting for the hypervisor to schedule physical CPU time.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. Check Real-Time Per-Core CPU Utilization with mpstat
Sample every logical CPU core (-P ALL) over three 1-second intervals to identify single-core saturation or asymmetric interrupt handling.
mpstat -P ALL 1 3
# Illustrative output (reviewed against documentation)
Linux 6.8.0-45-generic (prod-api-01) 10/22/2026 _x86_64_ (4 CPU)
18:10:01 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
18:10:02 all 28.50 0.00 4.25 0.50 0.00 2.25 0.00 0.00 0.00 64.50
18:10:02 0 94.00 0.00 5.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00
18:10:02 1 12.00 0.00 4.00 1.00 0.00 8.00 0.00 0.00 0.00 75.00
18:10:02 2 5.00 0.00 4.00 1.00 0.00 0.00 0.00 0.00 0.00 90.00
18:10:02 3 3.00 0.00 4.00 0.00 0.00 0.00 0.00 0.00 0.00 93.00
While the aggregate 'all' line shows 64.50% idle capacity, inspecting individual cores reveals that CPU 0 is 100% saturated (94% user, 5% sys, 0% idle) by a single-threaded worker.
2. Capture Non-Interactive Top CPU Processes Using top Batch Mode
Run top in batch mode (-b) for two iterations (-n 2) with a 1-second delay (-d 1) to capture an accurate real-time snapshot of the highest CPU-consuming processes.
top -b -d 1 -n 2 | awk '/^top -/{block++} block==2' | head -n 15
# Illustrative output (reviewed against documentation)
top - 18:12:04 up 42 days, 6:14, 1 user, load average: 1.42, 1.18, 0.95
Tasks: 184 total, 2 running, 182 sleeping, 0 stopped, 0 zombie
%Cpu(s): 27.8 us, 3.9 sy, 0.0 ni, 67.2 id, 0.3 wa, 0.0 hi, 0.8 si, 0.0 st
MiB Mem : 15984.2 total, 4120.5 free, 6210.8 used, 5652.9 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 9340.1 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
14892 www-data 20 0 1248500 184200 32100 R 98.9 1.1 45:12.80 node
2104 postgres 20 0 2184000 540120 512000 S 12.4 3.3 18:04.11 postgres
The first iteration of top -b -n 1 shows cumulative averages since boot; filtering for the second iteration (block==2) yields the true real-time CPU usage over the last 1-second window.
3. Monitor Per-Process CPU Breakdown with pidstat
Use pidstat (also included in the sysstat package) with -u to monitor live user, system, and guest CPU percentages per active process without clearing the screen.
pidstat -u 1 2
# Illustrative output (reviewed against documentation)
Linux 6.8.0-45-generic (prod-api-01) 10/22/2026 _x86_64_ (4 CPU)
18:15:00 UID PID %usr %system %guest %wait %CPU CPU Command
18:15:01 33 14892 92.00 6.00 0.00 0.00 98.00 0 node
18:15:01 114 2104 9.00 3.00 0.00 1.00 12.00 1 postgres
Notice the %wait column in pidstat: it measures the percentage of time the task was runnable but waiting in the scheduler run-queue for a CPU core to become free.
4. Correlate CPU Saturation, Run-Queue Depth, and Context Switches with vmstat
Run vmstat 1 4 to inspect system-wide runnable threads (r), blocked I/O threads (b), context switches (cs), interrupts (in), and CPU state percentages.
vmstat 1 4
# Illustrative output (reviewed against documentation)
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 0 4219392 312400 5476120 0 0 12 48 840 1920 26 4 69 1 0
1 0 0 4219100 312400 5476120 0 0 0 64 1120 2410 29 5 66 0 0
2 0 0 4218840 312400 5476124 0 0 0 32 1085 2305 28 4 68 0 0
1 0 0 4218840 312400 5476124 0 0 0 16 990 2180 27 4 69 0 0
Always ignore the very first data row of vmstat (which reports boot-time averages). When the 'r' (runnable) column consistently exceeds your total vCPU count (nproc), threads are queuing for CPU cycles.
5. List the Top 10 CPU-Intensive Processes Sorted by %CPU Using ps
Query the process table directly using ps aux --sort=-%cpu to list processes with the highest lifetime CPU utilization ratio.
ps -eo pid,user,ppid,ni,pri,psr,%cpu,%mem,etime,comm --sort=-%cpu | head -n 6
# Illustrative output (reviewed against documentation)
PID USER PPID NI PRI PSR %CPU %MEM ELAPSED COMMAND
14892 www-data 1102 0 19 0 84.2 1.1 02:14:10 node
2104 postgres 1890 0 19 1 11.8 3.3 12-04:22:19 postgres
1045 root 1 0 19 2 2.1 0.8 42-06:18:01 containerd
892 root 1 -20 39 3 0.8 0.2 42-06:18:04 systemd-journal
612 root 2 0 19 1 0.3 0.0 42-06:18:09 kworker/1:1H
Including the PSR column reveals which logical processor core each process is currently assigned to, while NI shows the nice scheduling priority (-20 highest to +19 lowest).
6. Inspect Hardware and Software Interrupt Rates Across Cores
Use mpstat -I SUM -P ALL 1 1 to check whether a single CPU core is being overwhelmed by hardware or software interrupts from a network card or NVMe controller.
mpstat -I SUM -P ALL 1 1
# Illustrative output (reviewed against documentation)
Linux 6.8.0-45-generic (prod-api-01) 10/22/2026 _x86_64_ (4 CPU)
18:20:00 CPU intr/s
18:20:01 all 4820.00
18:20:01 0 410.00
18:20:01 1 3890.00
18:20:01 2 280.00
18:20:01 3 240.00
Here CPU 1 is handling 3,890 interrupts per second while CPUs 2 and 3 handle fewer than 300/s, indicating that irqbalance or RSS (Receive Side Scaling) should be tuned.
Real-World Workflows, Pipelines, and Shell Automation
Zero-Dependency /proc/stat Delta CPU Usage Calculator in Pure Bash
On minimal container images or embedded Linux hosts where sysstat (mpstat) is not installed, calculate exact real-time CPU utilization and I/O wait percentages over a 1-second window directly from /proc/stat.
#!/usr/bin/env bash
set -euo pipefail
read -r _ u1 n1 s1 i1 w1 irq1 sirq1 st1 _ < /proc/stat
sleep 1
read -r _ u2 n2 s2 i2 w2 irq2 sirq2 st2 _ < /proc/stat
prev_total=$((u1 + n1 + s1 + i1 + w1 + irq1 + sirq1 + st1))
curr_total=$((u2 + n2 + s2 + i2 + w2 + irq2 + sirq2 + st2))
diff_total=$((curr_total - prev_total))
diff_idle=$((i2 - i1))
diff_iowait=$((w2 - w1))
diff_steal=$((st2 - st1))
awk -v tot="${diff_total}" -v idl="${diff_idle}" -v iow="${diff_iowait}" -v stl="${diff_steal}" 'BEGIN {
busy = 100 * (tot - idl - iow) / tot;
printf "CPU_BUSY=%.2f%% IOWAIT=%.2f%% STEAL=%.2f%% IDLE=%.2f%%
", busy, (100*iow/tot), (100*stl/tot), (100*idl/tot);
}'
# Illustrative output (reviewed against documentation)
CPU_BUSY=32.75% IOWAIT=0.50% STEAL=0.00% IDLE=66.75%
Because /proc/stat is exported directly by the Linux kernel on every architecture, this delta technique requires zero third-party packages and runs with negligible overhead.
Automated JSON Per-Core Saturation Alert Pipeline
Use mpstat -o JSON -P ALL 1 1 piped into jq to detect and alert on any individual CPU core whose idle percentage drops below 5%.
mpstat -o JSON -P ALL 1 1 | jq -r '.sysstat.hosts[0].statistics[0]."cpu-load"[] | select(.cpu != "all" and .idle < 5.0) | "ALERT: Core CPU\(.cpu) saturated — usr=\(.usr)% sys=\(.sys)% soft=\(.soft)% steal=\(.steal)% idle=\(.idle)%"'
# Illustrative output (reviewed against documentation)
ALERT: Core CPU0 saturated — usr=94.00% sys=5.00% soft=1.00% steal=0.00% idle=0.00%
Checking individual cores (.cpu != "all" and .idle < 5.0) catches single-threaded bottlenecks in Node.js, Redis, or Python workers that aggregate host-wide CPU alerts completely miss.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding mpstat inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
Running high-frequency process table scrapers (such as top -d 0.05 or tight while loops spawning ps aux hundreds of times per second) on servers with tens of thousands of active threads causes severe contention on kernel /proc locks and increases %sys CPU overhead. Always use a sampling interval of at least 1 second on production hosts.
Aggregate CPU counters in /proc/stat and /proc/loadavg are readable by all local users so monitoring agents do not require root privileges. However, on hardened Linux servers where the /proc filesystem is mounted with the hidepid=2 or hidepid=invisible option, unprivileged users running top, htop, ps, or pidstat can only see processes owned by their own UID.
Consequently, if an unprivileged user runs mpstat or top on a hidepid=2 host, the system-wide CPU header will accurately report 95% CPU busy, while the process list appears empty if the CPU-intensive workload belongs to another service account. Run pidstat or top via sudo when diagnosing system-wide contention on hardened hosts.
GNU/Linux, BSD, and BusyBox Implementation Differences
The mpstat, pidstat, and sar utilities are part of the Linux-specific sysstat package and rely on the Linux /proc/stat format. Remember that inside Docker, Podman, or Kubernetes containers without lxcfs, /proc/stat reflects the underlying physical or VM host's total CPUs rather than the container's cgroup CPU quota; inside containers, inspect /sys/fs/cgroup/cpu.stat (cgroup v2) to measure container-scoped CPU usage and throttling (nr_throttled).
On FreeBSD and OpenBSD, use top -P (per-core display) or vmstat 1; on macOS, use top -l 2 -n 10 or powermetrics because neither /proc/stat nor Linux sysstat exists natively on Darwin.
Troubleshooting Common Errors and Diagnostics
Command 'mpstat' not found, or sar: Cannot open /var/log/sysstat/saXX
Root Cause: The sysstat package is not installed by default on minimal Debian/Ubuntu images, or its historical data collection timer (sysstat.service) is disabled in /etc/default/sysstat.
Resolution: Install the sysstat package and enable the systemd collection service if you also want historical sar CPU graphs.
sudo apt-get update && sudo apt-get install -y sysstat
sudo systemctl enable --now sysstat
mpstat or vmstat always reports the exact same unchanging CPU percentage
Root Cause: Running mpstat or vmstat with no interval argument prints the cumulative average CPU state since the system last booted rather than current live utilization.
Resolution: Always provide an interval and sample count (such as mpstat -P ALL 1 5 or vmstat 1 5) and evaluate the live delta samples.
mpstat -P ALL 1 5
High Load Average (e.g., 25.0) on a 4-CPU server while mpstat shows 80% idle
Root Cause: Linux includes threads stuck in uninterruptible I/O sleep (D state, waiting on slow disks or stale NFS mounts) in the Load Average calculation even though they consume zero CPU execution cycles.
Resolution: Check the %iowait column in mpstat and list processes in D state using ps to identify the storage bottleneck.
ps -eo pid,state,user,wchan:24,comm | awk '$1 == "PID" || $2 ~ /D/'
Alternatives, Related Commands, and Related Tutorials
- Diagnose OOM Killer Events in Linux: Logs & Memory Tuning — Practical syntax, flags, and examples for
dmesg. - How to Check Linux Version: Distro & Kernel Commands — Practical syntax, flags, and examples for
uname. - timedatectl Command in Linux: Time, Date & Timezones Guide — Practical syntax, flags, and examples for
timedatectl. - Check Listening Ports in Linux: ss, netstat & lsof Guide — Practical syntax, flags, and examples for
ss. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides


Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!