You are on page 1of 16

10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

HOME LEARNING SUBSCRIBE! WRITE FOR US PRIVACY TERMS 

Shop Now

Infinix Smart 5 (2GB | 32GB)


6000mAh Battery | 6.82" Screen

Linux Commands

How to Check CPU Utilization in


Linux
10 months ago • by Sidratul Muntaha

The performance of the CPU is one of the major determinants of the performance of a
system. To ensure the most out of the limited processing power, it’s necessary to monitor how
this resource is used. Monitoring the CPU performance can help debugging processes,
managing system resources, taking system decisions, and evaluating systems in real-time.

In this guide, check out how to check CPU utilization in Linux.

CPU utilization in Linux


The CPU is the primary source of all the processing power a computer offers. To get the most
out of it, it’s necessary to manage and optimize its usage.

Dashboard with KPI Metrics


From Shop Floor to Top Floor. One Solution.

https://linuxhint.com/check-cpu-utilization-linux/ 1/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now

Infinix Smart 5 (2GB | 32GB)


6000mAh Battery | 6.82" Screen

Shop Now

*T&C apply, limited period offer, for details visit flipkart.com

Modern operating systems are optimized to use the CPU as efficiently as possible. Even other
apps out there are quite optimized. However, users may not be. In my case, for example, I
play games while there are hundreds of browser tabs open and multiple background tasks
running. While all the software is optimized, my way of usage will cause a higher CPU load.

If multiple users are logged in, then the CPU usage will automatically be high. However, the
system admin may want to keep an eye on it to ensure that someone isn’t hogging all of it,
causing overall poor system performance and experience. If a certain process/app is causing
too much CPU usage, it may either be malfunctioning, bugged or that’s the nature of it.

Sometimes, unusual CPU usage may also indicate that there’s a system intrusion.

Based on all this information, checking CPU utilization can be quite insightful.

Check CPU utilization in Linux


In the case of Linux, there are numerous tools to monitor CPU usage. It has various built-in
system calls to extract performance readings. Some of the tools come pre-installed with all
Linux distros, some may require manual installation.

All the following methods are demonstrated on Ubuntu 20.04.1 LTS. However, they’ll work just
fine on any other modern distro.

https://linuxhint.com/check-cpu-utilization-linux/ 2/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now
Shop Now
Infinix Smart 5 (2GB | 32GB)
6000mAh Battery | 6.82" Screen *T&C apply, limited period offer, for details visit flipkart.com

Check CPU utilization using top


Using top, you can monitor the system in real-time. It reports a brief summary of system
information along with a list of processes and threads currently being managed by the Linux
kernel. It also offers interactive options to modify its behavior and perform various actions.

The top tool can show CPU utilization. Launch the tool.

$ top


https://linuxhint.com/check-cpu-utilization-linux/ 3/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now
Shop Now
Infinix Smart 5 (2GB | 32GB)
6000mAh Battery | 6.82" Screen *T&C apply, limited period offer, for details visit flipkart.com

Here, the key line to focus on is the third one. The output values are explained briefly. Each
value explains the amount of time the CPU spends performing something.

us: Time spent running processes for people in the “user space”.
sy: Time spent running “kernel space” processes.
ni: Time spent running processes with custom (manually set) nice value.
id: Time spent idle.
wa: Time spent waiting for I/O request completion.
hi: Time spent servicing hardware interrupts.
si: Time spent servicing software interrupts.
st: Time lost for running virtual machine, also known as “steal time”.

Now, you can sort and filter the process list with various hotkeys. Here, I’ve described the
ones that are associated with CPU usage.

P: Sort processes by CPU usage.


I: Remove idle processes from the list. To revert, press “I” again.
M: Sort the list by memory usage.
S: Sort the list by how long processes have been running.
U: Filter the processes by the owner.
K: Kill a process. Requires the PID of the process.

Check CPU utilization using htop


Htop and top both are essentially the same tools. They both offer the same features in terms
of system monitoring capability. However, htop offers a better quality-of-life experience.


https://linuxhint.com/check-cpu-utilization-linux/ 4/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now
Shop
The default display of the htop is more comfortable Now
to work with. The UI has better clarity than
Infinix
the top.Smart 5 (2GB
The texts | 32GB)and pleasant to look at. It also offers both horizontal and
are colorized
vertical scrolling.
6000mAh Battery | 6.82" Screen *T&C apply, limited period offer, for details visit flipkart.com

While most distros will have top installed by default, you have to install htop manually. It’s best
to install htop using snap as it works on any Linux distro. Assuming you have snappy (the
snap package manager) installed, run the following command.

$ sudo snap install htop

Launch htop.

$ htop

I’ll not discuss anything further as the usage of htop is the same as the top.

https://linuxhint.com/check-cpu-utilization-linux/ 5/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now
Shop Now
Infinix Smart 5 (2GB | 32GB)
6000mAh Battery | 6.82" Screen *T&C apply, limited period offer, for details visit flipkart.com

Check CPU utilization using iostat


The iostat tool reports CPU and I/O usage statistics. It’s a simple tool with simple output.
However, it will only report the statistics of the moment the tool was run. Unlike top or htop,
iostat doesn’t offer real-time system monitoring.

The iostat tool comes as a part of the sysstat package. It’s available on almost any Linux
distro. Assuming you’ve installed the sysstat package, let’s move on.

Launch iostat.

$ iostat

Interested in a more in-depth report? Use the “-c” flag to see CPU usage of user processes,
system processes, I/O wait, and idle time.


https://linuxhint.com/check-cpu-utilization-linux/ 6/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now
Shop Now
Infinix Smart 5 (2GB | 32GB)
6000mAh Battery | 6.82" Screen *T&C apply, limited period offer, for details visit flipkart.com

$ iostat -c

Use the flag “-x” for extended statistics. The flag “-t” will define how many times each report
should be displayed.

$ iostat -xtc 5 2

Check CPU utilization using mpstat


https://linuxhint.com/check-cpu-utilization-linux/ 7/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

The mpstat tool is a part of the sysstat package. The tool reports the usage of individual
₹8,999 PRICE DROP

processors or processor cores.

Shop Now

Infinix Smart 5 (2GB | 32GB)


6000mAh Battery | 6.82" Screen
Shop Now

To use mpstat, you have to have the sysstat package installed in your system. Assuming you
already have the package installed, let’s move ahead.

Launch mpstat.

$ mpstat

Here’s what the values mean. Each value describes the CPU usage at a certain level.

%usr: User-level CPU usage.


%nice: CPU usage by “nice” user processes.
%sys: CPU usage by the kernel.
%iowait: Waiting for disk read/write.
%irq: Handling hardware interrupts.
%soft: Handling software interrupts.
%steal: Forced waiting for a hypervisor handling virtual processors.
%guest: Running a virtual processor.
%idle: Standing idle.


https://linuxhint.com/check-cpu-utilization-linux/ 8/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Sponsored by Thermo Fisher Scientific

The Pharma Services/SampleManager LIMS collaboration is how Thermo


Shop Now

FisherSmart
Infinix Scientific
5 (2GBis driving...
| 32GB)
Leaders from Thermo Fisher Pharma Services’ Global Quality Systems team explain how the deployment of
6000mAh Battery
SampleManager | 6.82"
LIMS Screen
software supports the organization’s quality control strategy.
SEE MORE

Check CPU utilization using sar


The sar command is for collecting and reporting system activity information. It offers a short
and simple report about CPU utilization.

We can use sar to offer the CPU information at a certain interval (in seconds). While it’s not a
real-time report, it’s still better to work with.

$ sar<interval_second>

In the last example, sar would run infinitely. We can define how many instances sar will print
the output. In the following example, sar will print the output at 5 seconds interval, for 10
times.

$ sar 5 10


https://linuxhint.com/check-cpu-utilization-linux/ 9/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now

Shop Now

Infinix Smart 5 (2GB | 32GB)


6000mAh Battery | 6.82" Screen

Check CPU utilization using vmstat


The vmstat tool reports various system information like system processes, memory, swap,
CPU performance, and I/O.

Run vmstat. It’ll report the system information of the moment it was run.

$ vmstat

Similar to sar, vmstat can report the system status at a fixed interval (in seconds).

$ vmstat 3 
https://linuxhint.com/check-cpu-utilization-linux/ 10/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now

In the last step, vmstat would run infinitely. To run vmstat for a fixed period of time, define the
Infinix Smart 5 (2GB | 32GB)
number of runs. Here, vmstat will report system status at 3 seconds interval, for 10 times.
6000mAh Battery | 6.82" Screen
$ vmstat 3 10

Check CPU utilization using Glances


Glances is a powerful tool for monitoring system status. It’s written in Python that uses the
psutil library for grabbing various system information. Glances offer lots of in-depth system
info like CPU monitoring, memory, network usage, disk I/O, processes, and filesystem
utilization, etc. Check out Glances at GitHub.

Installing Glances is a simple task. The following method will work on any GNU/Linux distro.
All you need is to have either curl or wget installed in your system. Glances will be installed

https://linuxhint.com/check-cpu-utilization-linux/ 11/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

with all the necessary dependencies.


₹8,999 PRICE DROP

$ curl -L https://bit.ly/glances | /bin/bash

$ wget -O- https://bit.ly/glances | /bin/bash


Glances are also available as a snap package. Assuming you have snappy (snap package
manager) installed in your system, install Glances snap from Snapcraft. Check out Glances at
Snapcraft.
Shop Now

 $ sudo snap install glances


Infinix Smart 5 (2GB | 32GB)
6000mAh Battery | 6.82" Screen

Using Glances is very simple. To start the standalone mode, run the following command.

$ glances


https://linuxhint.com/check-cpu-utilization-linux/ 12/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

Glances also offer to run in web server mode. To start the webserver, run the following
₹8,999 PRICE DROP

command.

$ glances -w

Shop Now

Infinix Smart 5 (2GB | 32GB)


6000mAh Battery | 6.82" Screen

To access the server, go to the following URL.

$ http://<IP_address>:61208

For raw information output, Glances can print the output to STDOUT.


https://linuxhint.com/check-cpu-utilization-linux/ 13/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now

Infinix Smart
 $ glances 5 (2GB
--stdout | 32GB)
cpu.user,mem.used,load

6000mAh Battery | 6.82" Screen

Final thoughts
There are plenty of ways to get CPU utilization. While all of them work just fine, depending on
your necessity, you may have to stick with a few of them. If you’re a system admin, then
mastering top/htop and Glances offer the most flexibility. If you just want a quick update of the
system resource consumption, then other methods offer a better experience.

Checking CPU utilization is fine and useful. However, to ensure stability, it’s necessary to
verify that your system can function fine even under the maximum stress. Check out some
useful Linux apps to stress test and benchmark CPU performance.


https://linuxhint.com/check-cpu-utilization-linux/ 14/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Happy computing!

Shop Now
ABOUT THE AUTHOR
Infinix Smart 5 (2GB | 32GB)
6000mAh BatterySidratul Muntaha
| 6.82" Screen

Student of CSE. I love Linux and playing with tech and gadgets. I use both
Ubuntu and Linux Mint.

View all posts

RELATED LINUX HINT POSTS

How to Check OS Version from


Command Line

How to Use fdisk Command to


Create Partition in Linux

Linux Bluetooth Not Working


Troubleshooting

Linux Wc -C Option to Count


Bytes

How to Remove a Non-Empty


Directory in Linux

Creating A User with Different


Home Directory in Linux

How Do I Become a Root User in


Linux


https://linuxhint.com/check-cpu-utilization-linux/ 15/16
10/9/21, 5:04 AM How to Check CPU Utilization in Linux

₹8,999 PRICE DROP

Shop Now

Infinix Smart 5 (2GB | 32GB)


6000mAh Battery | 6.82" Screen

Linux Hint LLC, editor@linuxhint.com

1210 Kelly Park Cir, Morgan Hill, CA 95037

AN ELITE CAFEMEDIA PUBLISHER


https://linuxhint.com/check-cpu-utilization-linux/ 16/16

You might also like