System administrators often need to check CPU utilization in Linux to diagnose performance bottlenecks. Understanding how to check CPU utilization in Linux is a fundamental skill that helps you monitor system health, identify runaway processes, and optimize resource allocation. Whether you are managing a single server or a cluster of machines, knowing the exact CPU usage can save you from unexpected crashes and slowdowns.
In this guide, you will learn multiple command-line tools and methods to monitor CPU performance. We cover everything from quick glances with top to deep dives with perf. By the end, you will be able to pinpoint high CPU consumption and take corrective action.
How To Check Cpu Utilization In Linux
The most direct way to check CPU utilization is using the top command. It provides a real-time, dynamic view of system processes and their CPU usage. Simply open your terminal and type top. You will see a summary line at the top showing overall CPU percentages, followed by a list of processes sorted by CPU consumption by default.
Press q to exit top. This tool is available on almost every Linux distribution without extra installation. It is your first line of defense when investigating high load.
Using The Top Command For Real-Time Monitoring
When you run top, the header displays key metrics like load average, tasks, and CPU states. The CPU line shows percentages for user, system, nice, idle, iowait, hardware interrupt, software interrupt, and steal time. Pay attention to the %us (user) and %sy (system) values—they indicate how much CPU is used by applications versus the kernel.
To sort processes by a specific column, press P for CPU usage or M for memory usage. You can also press 1 to toggle individual CPU core views. This helps you see if one core is maxed out while others are idle.
Customizing Top Output
You can run top -b -n 1 to output a single batch snapshot, which is useful for scripting. Use top -u username to monitor only processes owned by a specific user. For continuous logging, combine -b with -d (delay) and redirect output to a file.
Checking CPU Usage With Htop
htop is an improved version of top with a color-coded interface and mouse support. It is not installed by default on many distributions, but you can install it with your package manager. For example, on Ubuntu: sudo apt install htop. On CentOS: sudo yum install htop.
Once installed, run htop. You will see a visual bar for each CPU core, making it easy to spot imbalances. You can scroll through processes vertically and horizontally. Use the F6 key to sort by a different column, like CPU percentage or memory.
Htop Interactive Features
You can kill processes directly from htop by selecting them and pressing F9. Press F2 to access the setup menu, where you can change colors, add meters, or adjust display options. Htop also shows a tree view (press F5) to visualize parent-child process relationships.
Using The Mpstat Command For Per-Core Statistics
The mpstat command is part of the sysstat package. It reports processor statistics per CPU core. Install it with sudo apt install sysstat or sudo yum install sysstat. Run mpstat -P ALL 2 5 to display statistics for all cores every 2 seconds, 5 times.
Output shows columns like %usr, %nice, %sys, %iowait, %irq, %soft, %steal, %guest, %gnice, and %idle. A high %iowait value indicates disk I/O bottlenecks rather than CPU saturation.
Mpstat In Scripts
You can use mpstat -P ALL without arguments to get a single snapshot. Combine with awk or grep to extract specific values for monitoring dashboards. For example, mpstat | awk '/all/ {print $3}' gives the overall user CPU percentage.
Using The Sar Command For Historical Analysis
sar is another tool from the sysstat package. It collects and reports system activity over time. To view CPU utilization from today, run sar -u. To see data from a specific date, use sar -u -f /var/log/sysstat/saDD where DD is the day number.
The output shows average CPU usage per interval (usually 10 minutes). This is invaluable for identifying trends or spikes that occured overnight. You can also use sar -P ALL to see per-core data.
Configuring Sar Data Collection
By default, sysstat collects data every 10 minutes. You can change the interval in /etc/sysstat/sysstat or /etc/cron.d/sysstat. Ensure the sysstat service is enabled: sudo systemctl enable sysstat and sudo systemctl start sysstat.
Checking CPU Load With Uptime And /Proc/Loadavg
The uptime command shows load averages for the past 1, 5, and 15 minutes. A load average of 1.0 on a single-core system means the CPU is fully utilized. On a quad-core system, a load of 4.0 indicates full utilization. Run uptime to see these numbers quickly.
For more detail, read the file /proc/loadavg with cat /proc/loadavg. It displays the same load averages plus the number of running and total processes. This is a lightweight way to check CPU pressure without installing tools.
Interpreting Load Averages
Load average includes processes waiting for CPU and I/O. So a high load does not always mean high CPU usage—it could be disk or network waits. Use top or iostat to distinguish between CPU and I/O bottlenecks.
Using The Ps Command For Process-Specific CPU Usage
The ps command can show CPU usage for individual processes. Run ps aux --sort=-%cpu to list processes sorted by CPU percentage. The %CPU column shows the percentage of CPU time used since the process started, which can be misleading for short-lived processes.
For more accurate real-time data, use top or htop. But ps is excellent for scripting. For example, ps -eo pid,pcpu,comm --sort=-pcpu | head -10 shows the top 10 CPU consumers.
Ps Output Fields
Common fields include pid (process ID), pcpu (CPU percentage), pmem (memory percentage), comm (command name), and user (owner). You can customize the output with the -o option.
Using The Pidstat Command For Per-Process Statistics
pidstat is part of sysstat and provides per-process CPU usage. Run pidstat 2 5 to display statistics every 2 seconds for 5 intervals. It shows the process ID, %CPU, command, and more. Use pidstat -p PID to monitor a specific process.
This tool is useful for isolating a single application’s CPU consumption over time. Combine with -r for memory stats or -d for I/O stats.
Pidstat For Threads
Add the -t flag to see CPU usage per thread within a process. This helps identify if a multi-threaded application is using threads efficiently.
Using The Perf Command For Advanced Profiling
perf is a powerful profiling tool for deep CPU analysis. It can count hardware events like cache misses, branch mispredictions, and CPU cycles. Install it with sudo apt install linux-tools-common or sudo yum install perf.
Run perf stat ls to count CPU events for the ls command. For live monitoring, use perf top to see which functions are consuming the most CPU. This is invaluable for developers optimizing code.
Perf Record And Report
Use perf record -a -g sleep 10 to sample all CPUs for 10 seconds with call graphs. Then run perf report to view the results. This shows which functions and call paths are using the most CPU time.
Using The Nmon Command For Interactive Monitoring
nmon provides a curses-based interface with real-time CPU, memory, disk, and network stats. Install it with sudo apt install nmon or sudo yum install nmon. Run nmon and press c to see CPU stats, m for memory, d for disks.
Press q to quit. Nmon can also log data to a file with nmon -f -s 30 -c 120 (every 30 seconds for 120 intervals).
Using The Glances Tool For Comprehensive Overview
glances is a cross-platform monitoring tool that shows CPU, memory, disk, network, and processes in a single screen. Install it with sudo apt install glances or sudo pip install glances. Run glances to see a color-coded summary.
Press 1 to toggle per-core CPU views, 2 for disk I/O, 3 for network. It also supports client-server mode for remote monitoring.
Using The Vmstat Command For System-Wide Stats
vmstat reports virtual memory statistics, including CPU. Run vmstat 2 5 to see system-wide averages every 2 seconds. The CPU columns show us (user), sy (system), id (idle), wa (waiting for I/O), and st (stolen by hypervisor).
This is a lightweight tool that gives a quick overview of CPU, memory, and I/O in one glance. It is available on all Linux systems.
Using The Iostat Command For CPU And Disk Together
iostat is part of sysstat and reports CPU utilization and disk I/O. Run iostat -c 2 5 to see CPU stats only. The output includes %user, %nice, %system, %iowait, %steal, and %idle.
Combine iostat -x for extended disk statistics to correlate high CPU with disk activity.
Using The Dstat Command For Real-Time Summary
dstat combines features of vmstat, iostat, netstat, and ifstat. Install it with sudo apt install dstat or sudo yum install dstat. Run dstat -c to see CPU stats only, or dstat -c --top-cpu to show the top CPU-consuming process.
It outputs a rolling average every second by default. You can customize the output with many plugins.
Using The /Proc/Stat File For Raw Data
The /proc/stat file contains raw CPU counters. Use cat /proc/stat | grep '^cpu' to see cumulative CPU time for each core. The columns represent user, nice, system, idle, iowait, irq, softirq, steal, guest, and guest_nice.
To calculate CPU usage percentage, sample two readings and compute the difference. This is how tools like top derive their numbers. It is useful for custom scripts.
Using The Inxi Command For System Info
inxi is a system information tool that includes CPU details. Install it with sudo apt install inxi. Run inxi -C to see CPU model, cores, and current load. It also shows temperature if sensors are available.
This is more of a hardware overview than real-time monitoring, but it helps understand your CPU capabilities.
Using The Sensors Command For Temperature
High CPU utilization often leads to high temperatures. Install lm-sensors with sudo apt install lm-sensors and run sensors to see CPU core temperatures. This helps you determine if thermal throttling is affecting performance.
Combine with watch -n 2 sensors to monitor temperature changes in real time.
Frequently Asked Questions
What Is The Easiest Way To Check CPU Utilization In Linux?
The easiest way is to run the top command. It shows real-time CPU usage for all processes and is available on every Linux distribution without extra installation.
How Can I Check CPU Usage Per Core In Linux?
Use mpstat -P ALL to see per-core statistics. Alternatively, press 1 while in top or htop to toggle individual core views.
What Does The Load Average Mean In Linux?
Load average represents the number of processes waiting for CPU or I/O over 1, 5, and 15 minutes. Compare it to the number of CPU cores to gauge saturation.
How Do I Monitor CPU Usage Over Time In Linux?
Use sar -u to view historical CPU data collected by sysstat. You can also log top output to a file with top -b -d 10 > cpu.log.
What Is The Difference Between %Us And %Sy In Top?
%us is CPU time spent on user processes (applications), while %sy is time spent on system (kernel) processes. High %sy may indicate driver issues or excessive system calls.
Conclusion
You now have a comprehensive toolkit to check CPU utilization in Linux. From quick commands like top and uptime to advanced profiling with perf, you can diagnose any performance issue. Start with top for immediate insight, then use mpstat or sar for deeper analysis. Remember to consider I/O wait and temperature as part of the bigger picture. Practice these commands regularly to become proficient in Linux performance monitoring.