Javatpoint Logo
Javatpoint Logo

CPU Utilization in Linux

One aspect of determining the system's efficiency is CPU performance.

Monitoring CPU performance is critical to debugging system processes, making system decisions, handling system resources, and inspecting and evaluating systems in real- time.

A variety of tools are available to track and view CPU performance. The operating system consists of built-in system calls that rely on these tools to extract performance readings. Now we talk about the great CPU usage monitoring tool and how to use it in any Linux distribution.

Used Top to Check CPU Utilization

With the help of the top command, we can monitor the system in real-time. When we execute the top command, it will provide us the summary of the system along with the list of threads and process which are presently being managed by the Linux kernel. It also offers various options in order to change its behaviour and perform several actions.

Syntax


CPU Utilization in Linux

In the above output, the main line to focus on is the line number third. The output values are briefly described. Each value indicates how much time the CPU spends performing a task.

  • us: The amount of time it takes to run the process for individual users in the "user space."
  • sy: sy is the time spent running "kernel space" processes.
  • ni: ni is the time spent to run the process with a custom (manually set) excellent value.
  • id: id is the time spent idle.
  • wa: wa means the amount of time spent waiting for I/O request to complete.
  • hi: hi is the time spent servicing hardware interrupts.
  • si: si is the time spent servicing software interrupts.
  • st: st is the time lost for running a virtual machine, which is also called "steal time."

Check CPU Utilization Using htop Command

The top and htop commands are the same. In terms of system monitoring both commands offer the same functionality. On the other hand, the htop command offers a better quality-of-life experience. The htop's default display is more user-friendly. As compared to the top, the htop UI has better quality. In this, we can also scroll horizontal as well as vertical.

In most of the distros, the top is installed by default, and we have to install the htop manually. The best way to install the htop is using snap because it works well on any of the Linux distros. Following is the syntax which we use to install htop:

Syntax of htop:


CPU Utilization in Linux

Check CPU Utilization Using iostat

The iostat command reports CPU and I/O usage statistics. This command is simple with simple output. Although, it will only report data on the moment the command was run. iostat does not provide real-time system monitoring, unlike top and htop.

The iostat tool comes as a part of the sysstat package. Mostly this command is available on every Linux distro. Suppose we have installed the sysstat package, then run.

Launch iostat:


CPU Utilization in Linux

If we want to know more detail, then we can use the -c flag to check the CPU usage of system processes, I/O wait, idle time, and user processes.

Syntax


CPU Utilization in Linux

The "-x" flag can be used to get more details statistics. The "-t" flag specifies the number of times each report must be shown.


CPU Utilization in Linux

Use mpstat to Check CPU Utilization

The mpstat tool is a part of the sysstat package. The tool reports the use of an individual processors or processor cores.

If we want to use the mpstat command, then it is a must that the sysstat package is installed in our system. Let's say we already have the package installed then proceed.

Launch mpstat:


CPU Utilization in Linux

Now we will explain each value in detail, and each value defines the usage of CPU at a specific stage.

  • %usr: It means the user-level CPU usage.
  • %nice: It implies the usage of CPU by "nice" user processes.
  • %sys: %sys means the CPU usage by the kernel.
  • %iowait: Waiting for disk read/write is expressed as %iowait.
  • %irq: Handling hardware interrupts is referred to as %irq.
  • %soft: Handling software interrupts is known as %soft.
  • %steal: The term %steal refers to having a wait for a hypervisor in order to handle virtual processors.
  • $idle: %idle means standing idle.

Use sar to Check CPU Utilization

Using the sar command, we can gather and report system activity information. This command will provide you a simple and short report related to CPU utilization.

Sar command may also be used to provide the CPU information at a regular interval (in seconds). It is not a real-time report; it is still better to work with it.

We are also able to define the number of times the sar will print the output. In this below example, the sar will print the output at 4 seconds intervals, for 8 times.


CPU Utilization in Linux

Check CPU Utilization Using nmon Command

nmon is a system administration tool that we used to get the information about CPU, Top process memory, etc. We can install the nmon command by using the following command:


CPU Utilization in Linux
Next TopicLinux Terminal




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA