Linux Command to Check CPU Utilization
Last Updated :
21 Jan, 2025
Checking CPU utilization is essential for maintaining system performance and identifying system issues. In Linux, various commands such as top, mpstat, sar and iostat provide real-time insights into how your CPU is being used, helping you understand workload distribution and optimize resource management.
Whether you're troubleshooting system slowdowns or analyzing performance for heavy applications, these commands offer clear and actionable data.
This article covers the most effective Linux commands to check CPU utilization, ensuring you have the tools to keep your system running smoothly.
How to Check CPU Utilization in Linux with Command Line
Here are the following commands to check the CPU Utilization in Linux and their working to view and interpret CPU usage:
Check CPU Utilization by top command
The top
command offers a dynamic, real-time view of running processes, displaying CPU and memory usage. By default, processes are listed in order of CPU consumption, allowing you to identify resource-intensive tasks easily. Pressing '1' within top
displays CPU statistics for individual cores.
In your Linux terminal, write this top command:
top
This will display a real-time overview of system processes, CPU, and memory usage.
The upper section provides system summary information, including:
- Uptime: How long the system has been running.
- User Sessions: Number of active user sessions.
- Load Average: System load over the past 1, 5, and 15 minutes.
- Tasks: Total number of tasks and their states (running, sleeping, stopped, zombie).
- CPU Usage: Percentage breakdown of CPU usage across different modes (user, system, idle, etc.).
- Memory Usage: Information on total, used, free, and cached memory.
The lower section lists active processes with details such as:
- PID: Process ID.
- USER: Owner of the process.
- PR: Priority of the process.
- %CPU: CPU usage percentage.
- %MEM: Memory usage percentage.
- TIME+: Total CPU time consumed by the process.
- COMMAND: Command that initiated the process.
To hides all the idle processes in the system, and making it easier to sort through the list, use top -i:
top -i
To quit the top
function, press q.
Some other useful commands while top
is running include:
M
- sort task list by memory usage.P
- sort task list by processor usage.N
- sort task list by process ID.T
- sort task list by run time.
Check CPU Utilization mpstat Command
The mpstat
command in Linux provides detailed processor-related statistics, making it a valuable tool for monitoring CPU performance, especially in multi-processor systems.
Ensure the sysstat
package, which includes mpstat
, is installed:
sudo apt install sysstat
After installation, execute mpstat
to display CPU usage statistics:
mpstat
To view statistics for a specific processor (e.g., CPU 0):
mpstat -P 0
To display statistics for all processors:
mpstat -P ALL
To capture multiple snapshots at defined intervals (e.g., every 5 seconds, 7 times):
mpstat 5 7
Understanding mpstat
Output:
The output includes several columns, each representing a specific CPU metric:
- %usr: CPU time spent in user mode.
- %nice: CPU time for user processes with a positive nice value.
- %sys: CPU time spent in system (kernel) mode.
- %iowait: CPU time waiting for I/O operations to complete.
- %irq: CPU time handling hardware interrupts.
- %soft: CPU time handling software interrupts.
- %steal: CPU time involuntarily waiting while the hypervisor services another virtual processor.
- %guest: CPU time running virtual processors.
- %idle: CPU idle time.
Check CPU Utilization iostat Command
Theiostat
command in Linux is a powerful utility for monitoring system input/output (I/O) statistics, providing insights into CPU utilization and disk I/O performance.
To display CPU and device I/O statistics:
iostat
To display statistics at regular intervals (e.g., every 2 seconds):
iostat 2
Check CPU Utilization sar Command
The sar
(System Activity Reporter) command in Linux is a versatile tool for monitoring system performance, providing real-time and historical data on various system metrics.
To display CPU utilization:
sar -u 5
To display memory usage:
sar -r
To display network statistics:
sar -n DEV
In Linux, several commands provide detailed information about your system's CPU. Here's an overview of some essential tools:
1. nproc
Command:
The nproc
command displays the number of processing units available. This is particularly useful when assessing system load or performance.
The nproc
command displays the number of processing units available. This is particularly useful when assessing system load or performance.
Display Total Processing Units:
nproc --all
This command outputs the total number of processing units, calculated as:
Threads per core × Cores per socket × Sockets
Exclude Specific Processing Units:
nproc --ignore=N
Replace N
with the number of processing units to exclude from the count.
2. dmidecode
Command
The dmidecode
command extracts hardware information from the system's Desktop Management Interface (DMI) or System Management BIOS (SMBIOS). It provides details about the BIOS, system, motherboard, chassis, cache, and CPU. Superuser privileges are required to execute this command.
Run dmidecode
:
sudo dmidecode
Filter for Processor Information:
sudo dmidecode | grep -i processor
This command filters the output to display only lines containing the term "processor".
3. inxi
Command
The inxi
command provides comprehensive system information, including CPU details. It may not be installed by default but can be added from standard repositories.
Display Basic System Information:
inxi -b
This command provides an overview, including CPU make and model, speed, kernel version, uptime, memory, storage, running processes, shell, and the inxi
version.
4. cpuid
Command
The cpuid
command retrieves detailed information about the x86 CPU, including vendor ID, version, features, and other specifications. It is not installed by default but can be installed from standard repositories.
Run cpuid
:
cpuid
This command outputs extensive details about the CPU, providing a comprehensive understanding of the processor installed on your system.
These commands are invaluable for system administrators and users seeking to gather detailed CPU information on Linux systems. They assist in performance assessment, troubleshooting, and system optimization.
Similar Reads
How to Check CPU Information on Linux? CPU Info Commands Checking of CPU data helps system administrators in learning about performance profiles, hardware constraints, and resource planning. CPU information assists developers in optimizing software for given architectures, resolving performance problems, and analyzing system use.Linux offers many differen
12 min read
7 Ways to Check CPU Clock Speed in Linux In general, a higher clock speed means a faster CPU. However, many other factors come into play. Your CPU processes many instructions (low-level calculations like arithmetic) from different programs every second. The clock speed measures the number of cycles your CPU executes per second, measured in
2 min read
How to Use Linux lscpu Command In the Linux environment, the lscpu command is an important utility for getting detailed information about the CPU (Central Processing Unit) configuration of our system. When this command is been executed, it provides the overview of the CPU architecture such as the CPU family, model, number of core
5 min read
Check and Monitor Active GPU in Linux Monitoring the GPU(Graphics Processing Unit) on a Linux operating system is essential for performance testing, debugging, and ensuring usage. There are many tools for checking and monitoring the GPU activity of various GPUs like Nvidia, AMD, or Intel GPU. This article will teach us about multiple me
4 min read
Linux stress command With Examples The 'stress' command is a robust command-line tool available on Linux-based operating systems. It's designed to assess the performance and reliability of hardware and software by simulating a high-load environment. Here we will cover everything from installation to practical usage.Introduction to "s
5 min read
ACPI command in Linux with examples ACPI is the command in Linux that helps the users in managing power settings. It also helps in monitoring the hardware status efficiently. It facilitates with providing essential information such as battery health, CPU temperatures, and fan speeds, providing support in system maintenance and perform
4 min read