Linux

How to Check CPU Utilization in Linux using Command Line?

Introduction

Any kind of system administrator who wants to gauge the performance of a system needs to constantly track the CPU. You could afterward manage system resources, troubleshoot system processes, and arrive at system decisions with this assistance. For measuring commands to check CPU utilization in Linux, there are various programs available. You can examine Linux CPU usage in several ways, as this post will show you.

Understanding the way to check Linux’s CPU usage via the command line is essential for everyone from Linux users to system administrators.

Also Read: How Can I Check Memory Usage in Linux?

How To Check CPU Usage from Linux Command Line

top Command to check the Linux CPU Load

Launch a terminal window, then type the following:

top
top Command to check the Linux CPU Load

A list that consists of every active process could be shown as the system’s response. Additionally, it will display the number of users, open tasks, CPU load CPU usage, along with memory usage.

As an outcome of both the start and finish of background tasks, this list will regularly change. Launching the top with the -i switch can be useful:

top –i

This conceals all the inactive processes and makes it simpler to browse the list.

Hit the letter q on the keyboard to end the top function.

Whenever the top is active, the following additional useful commands can be used:

  • M – arrange the job list per memory use
  • P – arrange the task list according to CPU usage.
  • N – order the task list by the process ID
  • T – order the task list according to run time

The letter h can be pressed when the top is functioning to receive help. On the other hand, you could type something like this at a command line:

man top

When you do so, the top command’s instructional page will appear.

mpstat Command for displaying CPU Activities

Mpstat is a component of the sysstat suite of programs. This program is present in the majority of RHEL-based releases.

Installing the sysstat package is necessary for Debian or Ubuntu systems.

Put the following information into a terminal window:

sudo apt-get install sysstat
top Command to check the Linux CPU Load

Give the procedure time to finish.

Give the procedure time to finish.

You can utilize up2date to set up sysstat when you’re using an earlier (4.x or earlier) edition of CentOS and a Red Hat derivative:

sudo update install sysstat

The syntax that follows can be used to installing sysstat on CentOS as well as Red Hat 5.x especially newer installations:

sudo yum install sysstat

After it gets finished, execute the mpstat command outlined below in the terminal:

mpstat
mpstat

For every processor (or processing core), the system shows its consumption.

A list of column names appears on the first line. Values for each column are shown on the second line:

  • %usr – % CPU consumption on a per-user basis
  • %nice – % CPU consumption for user operations marked “nice”
  • %sys – % System-level (Linux kernel) CPU utilization Linux
  • %iowait – % CPU waiting for a disc read/write while being inactive
  • %irq – % Processing hardware interrupts with Linux CPU usage
  • %soft – % CPU utilization in Linux handling software interruptions
  • %steal – % Waiting for a hypervisor to handle additional virtual processors, which delays CPU usage Linux.
  • %guest – % CPU utilization imposed by operating a virtual processor
  • %idle – % CPU utilization when not in use (i.e., when not waiting for a disc read/write)

This means that you can add switches to your mpstat command.

With the -P switch, you can choose just one processor to report on:

mpstat –P 0

A report containing information for CPU 0—the primary processor—would get displayed as an outcome.

mpstat –P ALL

Similar to the fundamental mpstat command, this command will show the total. In addition, it lists processes according to each CPU.

The mpstat command simply generates a check CPU utilization in Linux.

You can capture a series of pictures by specifying an interval with one number and the number of reports with another number:

mpstat 5 7

mpstat command

7 photos, each taken at a 5-second interval, would get produced in this case.

sar Command for Checking CPU Utilization

System resource management is possible with the sar tool. The -u option allows you to monitor CPU performance without getting restricted to just CPU consumption.

You can direct sar to check the CPU utilization in Linux at predetermined intervals by using the following command:

sar –u 5

It is going to show CPU use if the -u option gets used. It should update every five seconds, as indicated by the number 5. Ctrl-C can be used for canceling.

iostat Command to provide Average Utilisation

Fill out the information that follows in a terminal:

iostat

The standard CPU utilization during the last boot will get shown by the system. Additionally, it will show disc read/write activity and input/output workload.

iostat command

Other Options to Monitor CPU Performance

Other Options to Monitor CPU Performance

Nmon Monitoring Tool

IBM employee Nigel Griffiths created the monitoring program Nmon. Put in the following information to set up Nmon in Ubuntu:

sudo apt-get install nmon

Switch to the following information to set up CentOS:

sudo yum install epel-release
sudo yum install nmon
Nmon Monitoring Tool
Nmon Monitoring Tool

Launching nmon requires the following command:

nmon

By doing so, the utility will start up and show all the available options. Click the letter “c” to gain insight into Linux command CPU utilization. Hit C once more to return to the previous selection. Hit “h” to display a list of commands. Hit “q” to stop.


Pressing c

Graphical Utility Option

The usage of a graphical user interface (GUI) is often not wasted in server systems.

You may use a client Linux system or just a lightweight GUI, however, A few of the versions—like Ubuntu—include a graphical monitoring tool.

Enter the following syntax in a terminal window to start Ubuntu’s system supervision:

  • gnome-system-monitor

This launches a program that appears to be a task manager along lets you keep an eye on your assignments and CPU usage in Linux.

A program called “task manager” and “system monitor” is typically included on GUIs. The real-time command to check CPU utilization in Linux can be evaluated with this.

Also Read: How to List Users and Groups in Linux? {4 Easy Ways}

Conclusion

In the context of Linux, you can monitor CPU usage using a variety of techniques.

Using either third-party apps or the default Linux resources, this post identifies the essential techniques. With the assistance of these instruction sets, you can more accurately monitor the system’s performance & CPU consumption.

Hostbillo Team

The blogs are written by a team of in-house technical content experts. They handle everything from research to writing and publishing.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *