PC Components

How To Check CPU Usage in Linux

Linux Terminal

One thing common with using a Linux PC is that you have to type a couple of codes to get around. So, if you want to monitor the CPU performance to manage resources, debug system processes, or make system decisions, you must know the correct code. So, how do you check CPU usage on Linux? 

Quick Answer

To check the CPU usage on your Linux PC, you have to navigate to the Command Prompt or Terminal in Ubuntu or CentOS, for example. In the Terminal window, navigate with a series of Linux command lines until the CPU usage information is reached. 

You need access to a user account with sudo privileges to check the CPU usage on a Linux-based computer. Also, you will need a package installer like yum or apt, which is often included by default. Keep reading this article to learn more about how to check resource stats in Linux. 

Methods To Check Linux-Based PCs Resources Stats 

There are different ways to check resources stat on a Linux-based PC. It may seem a bit technical, especially if you are new to using Linux. However, below we highlighted the process of checking CPU usage on a Linux-based PC in four easy-to-comprehend methods.  

Method #1: Using the “top” Command 

This is the most common method to check resources stat on a Linux-based PC. When used right, you should be able to check the resources stat of processes currently running on your PC. You can then kill tasks from this menu if you wish. 

Here’s how to use the Top command.

  1. On your Linux PC, open the Terminal by pressing the Ctrl + Alt + T.
  2. Type top in the terminal window and press the Enter key.  Your PC should displace a list of all processes running on your PC. 
  3. You can launch top with the – i switch, which helps to hide all idle processes
  4. To quit, type the q and press the Enter key
Quick Tip

Other useful commands you can use while on top are the T function to run time, the N function to sort by process ID, the P function to sort by processor usage, and the M function to sort by memory usage.

Method #2: Using the “mpstat” Command 

Another common method to check resources stat on a Linux PC is the mpstat command. This command line is quite common, particularly for Ubuntu and Debian systems. However, note that you may have to install a sysstat package to run this command. 

Here’s how to use the mpstat command.

  1. On your Linux PC, open the Terminal by pressing the Ctrl + Alt + T.
  2. Type sudo apt-get install sysstat in the terminal window and press the Enter key
  3. When the process is complete, enter the command mpstat to displace the CPU usage for each process or core. 
Quick Note

You can add switches to the mpstat command to allow you to specify the report its displays.

Method #3: Using the “sar” Command 

Another way to check the CPU usage on a Linux PC is to use the sar command. This command is handy when you want to manage your system resources. The sar command is not limited to checking CPU usage; you can also use it to track CPU performance with the correct code option. 

Here’s how to use the sar command.

  1. On your Linux PC, open the Terminal by pressing the Ctrl + Alt + T.
  2. Enter sar –u 5 in the terminal window, and press the Enter key
  3. Your CPU usage will be displayed on your screen; to exit, press Ctrl + C.
More Info

The –u option added will tell the command prompt to display CPU usage, and 5 will update the info every 5 seconds.

Method #4: Using the Nmon Monitoring tool 

The Nmon tool is another useful tool that works on the Linux PC, which you can use to monitor the CPU usage on your PC. The Nmon tool was developed by Nigel Griffiths of IBM and can easily be installed on Ubuntu or CentOS. 

Here’s how to use the Nmon tool.

  1. Install the Nmon tool on Ubuntu by opening the Terminal and typing sudo apt-get install nmon.
  2. With Nmon installed, type the nmon command to launch the utility. 
  3. Type c to view CPU usage and c again. 
Take Note

You can install the Nmon tool on CentOS well using the command sudo yum epel-release for the first line. On the next line, type sudo yum install nmon.

Conclusion 

Checking the CPU usage on a Linux PC is fairly straightforward once you know the right command to use. There are many ways to check the CPU usage on a Linux PC other than the methods elaborated in this guide. However, this method highlighted in this guide is the primary method to check resources stat with built-in Linux tools or some third-party apps. 

Leave a Comment

Your email address will not be published.