Accurate CPU usage information on Linux highlights which workloads are actively consuming processing time and whether the system still has spare capacity. Understanding where cycles are spent helps balance background jobs with interactive work and prevents slowdowns under heavy load.
Utilities such as top, htop, mpstat, sar, and vmstat read kernel statistics from /proc and present them as percentages of user, system, idle, and waiting time. Some tools concentrate on individual processes, while others aggregate CPU usage per core or across the entire machine to expose trends and contention.
Each tool suits a slightly different scenario, from quick interactive checks to scheduled, long-term monitoring. Several commands require extra packages like htop or the sysstat suite, and historical reporting depends on an enabled data collection service, so enabling these components on Ubuntu or other distributions is an important prerequisite before relying on the readings.
Method 1: Using top
Method 2: Using htop
Method 3: Using mpstat
Method 4: Using sar
Method 5: Using vmstat
Steps to display CPU usage information using top:
Top is a standard process monitor on Linux that continuously refreshes a list of running tasks along with CPU usage, memory consumption, and load averages. The default view quickly highlights which processes are consuming the most CPU time.
Keyboard shortcuts change the sort order, toggle per-CPU views, and adjust how frequently the display refreshes. These controls make top effective for spotting brief spikes that might be missed by slower, one-shot commands.
- Open a terminal on the Linux system.
- Run the top command to display live CPU usage and process information.
$ top top - 12:00:00 up 10 days, 3:42, 1 user, load average: 0.35, 0.28, 0.20 Tasks: 200 total, 1 running, 199 sleeping, 0 stopped, 0 zombie %Cpu(s): 3.0 us, 1.0 sy, 0.0 ni, 96.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st ##### snipped #####
The %Cpu(s) summary line shows overall CPU usage, while the \%CPU column in the process list shows per-process CPU consumption.
- Press 1 to toggle between an aggregate CPU line and per-CPU statistics if supported.
Per-core usage helps identify single-threaded workloads saturating a single CPU while others remain mostly idle.
- Press Shift+P to sort processes by CPU usage.
Sorting by CPU makes persistent CPU hogs stand out even when the overall load is moderate.
- Press q to exit the top interface when monitoring is complete.
Steps to display CPU usage information using htop:
Htop provides an ncurses-based interface that extends top with colour bars, scrollable lists, and direct process management. CPU usage appears as stacked bars for each core, making saturation and idle periods easy to see at a glance.
Interactive keys support filtering, changing the sort column, and sending signals to processes. This makes htop useful not only for observing CPU usage but also for quickly terminating or renicing problematic tasks.
- Install the htop package from the distribution repository if it is not already available.
$ sudo apt update && sudo apt install --assume-yes htop
On Fedora and RHEL, install htop with sudo dnf install htop; on openSUSE, use sudo zypper install htop.
- Run the htop command to open the interactive CPU usage viewer.
$ htop 1 [|||||||||| 20.0%] Tasks: 120, 1 running ##### snipped #####
Coloured bars at the top show per-CPU, memory, and swap usage, while the main table lists individual processes.
- Press F6 and choose CPU as the sort column to list processes by CPU usage.
Sorting on CPU usage makes long-running, CPU-intensive tasks easy to spot even when the system load fluctuates.
- Select a process and press F9 to send a signal such as SIGTERM when terminating misbehaving tasks is required.
Stopping important system services or desktop components can cause crashes or disconnect remote sessions, so confirm a process role before sending signals.
- Press F10 to exit htop when finished reviewing CPU usage.
Steps to display CPU usage information using mpstat:
Mpstat belongs to the sysstat suite and reports CPU usage statistics per processor and for the system as a whole. Instead of listing processes, it focuses on how much time each CPU spends in user, system, idle, and wait states.
Sampling at fixed intervals produces concise, machine-readable tables that are easy to log or feed into monitoring systems. This makes mpstat suitable for identifying sustained imbalances between cores or prolonged periods of high system time.
- Install the sysstat package so that mpstat is available on the system.
$ sudo apt update && sudo apt install --assume-yes sysstat
On Fedora or RHEL, use sudo dnf install sysstat; on openSUSE, use sudo zypper install sysstat.
- Run mpstat without arguments to print a single snapshot of CPU usage since boot.
$ mpstat Linux 5.4.0-74-generic (hostname) 08/28/2024 _x86_64_ (4 CPU) 12:00:00 CPU %usr %nice %sys %iowait %irq %soft %steal %idle %guest 12:00:00 all 3.20 0.00 2.10 0.10 0.00 0.30 0.00 94.30 0.00
The all row summarises usage across all CPUs, while additional rows appear for each logical CPU on multi-core systems.
- Run mpstat with an interval and count to monitor CPU usage over time.
$ mpstat 2 5
The command mpstat 2 5 samples CPU statistics every two seconds for five iterations to capture short bursts of activity.
- Inspect the \%usr, \%sys, and \%idle columns to determine whether user workloads or kernel activity dominate CPU time.
A consistently low \%idle value indicates sustained high utilisation and potential CPU saturation.
Steps to display CPU usage information using sar:
Sar, also part of the sysstat suite, focuses on collecting and reporting historical performance data. For CPU usage it can replay snapshots covering previous minutes, hours, or days, depending on how long the data collection service has been active.
Data typically comes from binary log files in /var/log/sysstat, which are updated by a scheduled cron job or systemd timer. Sampling at regular intervals enables trend analysis and capacity planning that goes beyond what one-off real-time tools provide.
- Ensure the sysstat package is installed so that sar and its collectors are available.
$ sudo apt update && sudo apt install --assume-yes sysstat
Historical sar reports require that the sysstat data collection service is enabled; on many systems this is controlled by a configuration toggle or a systemd timer unit.
- Run sar with the -u option, an interval, and a count to display live CPU usage samples.
$ sar -u 1 5 Linux 5.4.0-74-generic (hostname) 08/28/2024 _x86_64_ (4 CPU) 12:00:00 CPU %user %nice %system %iowait %steal %idle 12:00:01 all 3.20 0.00 2.10 0.10 0.00 94.60 12:00:02 all 3.00 0.00 1.80 0.00 0.00 95.20 12:00:03 all 2.50 0.00 2.00 0.00 0.00 95.50 12:00:04 all 2.80 0.00 1.90 0.00 0.00 95.30 12:00:05 all 2.90 0.00 2.10 0.00 0.00 95.00
The \%user, \%system, and \%idle columns show where CPU time is spent during each sampling period.
- Use sar without an interval to read CPU statistics from stored log files for a given day.
$ sar -u ##### snipped #####
Historical output helps confirm whether CPU spikes are isolated incidents or part of a recurring pattern.
Steps to display CPU usage information using vmstat:
Vmstat reports a concise summary of processes, memory, paging, block I/O, interrupts, context switches, and CPU usage. Combining these metrics gives a broader view of system health than CPU-focused tools alone.
By running at short intervals, vmstat shows whether high CPU usage correlates with memory pressure, heavy disk I/O, or excessive context switching, which helps track down the true source of performance problems.
- Run vmstat with an interval and count to display CPU and system statistics over time.
$ vmstat 2 5 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 500000 60000 300000 0 0 0 0 100 200 3 1 96 0 0 0 0 0 499000 61000 300500 0 0 0 0 105 205 2 1 97 0 0 0 0 0 498000 62000 301000 0 0 0 0 110 210 1 1 98 0 0 0 0 0 497000 63000 301500 0 0 0 0 115 215 3 2 95 0 0 0 0 0 496000 64000 302000 0 0 0 0 120 220 4 1 95 0 0
The columns under the cpu heading show user time (us), system time (sy), idle time (id), and time spent waiting on I/O (wa).
- Run vmstat with only an interval argument for continuous monitoring.
$ vmstat 1
- Press Ctrl+C to stop continuous vmstat output when sufficient data has been observed.
- Review the cpu columns to confirm whether the system spends most time idle or whether sustained high us or sy values indicate CPU saturation.
A high wa percentage with modest us and sy values usually points to storage bottlenecks rather than pure CPU limits.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
