Understanding CPU utilization in Linux: Site24x7 (2024)

CPU utilization is the amount of work a CPU does to perform the tasks given to it. It’s an important metric to track because high CPU usage can negatively impact the performance of a system.

CPU usage can vary according to the CPU core count, since the system performs faster and more efficiently in the case of a higher core system. If the CPU cores are unable to handle the heavy load of an application, it results in context switching of tasks. But too much context switching will also cause a rise in CPU usage.

Tracking and monitoring CPU efficiency are essential for handling system processes and resources. Luckily, there are a number of tools available to monitor this metric.

Causes of high CPU utilization

Since high CPU utilization indicates poor system performance, it should be avoided. Higher than average CPU usage can often be attributed to one of the following causes:

1. System idle process

If a system is idle, the OS creates a process called the System Idle Process to prevent the system from shutting off. This process appears to show high CPU usage, but it actually indicates the percentage of CPU capacity not being used. If the idle process is taking up to 99% of the CPU's power, it means only 1% is being used to run actual tasks.

2. Autostart programs and background processes

Autostart programs are applications that are launched automatically when booting the operating system and they continue to run in the background. Too many background processes running simultaneously on a computer consume CPU resources and unnecessarily cause high CPU usage.

3. Virus and malware

If a system becomes extremely slow with a CPU usage of nearly 100%—but with no clear cause—the problem may be a virus or malware. These are often invisible and heavily utilize the CPU.

4. Browser

Even the browser can cause high CPU usage if:

  • Several tabs are opened at the same time
  • Multiple plugins and add-ons are running in the background
  • Browser tabs with ads or auto-playing videos are open

5. Programs with high CPU requirement

Applications or programs that require high processing power, including video editing software and high-resolution video games—can easily drive up CPU usage.

Effects of high CPU utilization

High CPU utilization adversely impacts system performance in the following ways:

  • Lag in CPU performance
  • Frequent rebooting of systems
  • Delay in response from application
  • Overheating of CPU

It's essential to check the CPU usage regularly to understand the cause and impact of high CPU utilization.

top Command

The top command is used to display a real-time, dynamic view of a running system. It displays various crucial system metrics along with a set of processes that are currently being managed by the Linux kernel. It is one of the most widely used commands for tracking the CPU utilization, process statistics, and memory utilization of a Linux system.

For example, running the top command on a Linux system will display an output similar to the one shown below:

Understanding CPU utilization in Linux: Site24x7 (1) Fig 1: Output of top command

In the output above, the top command displays various important CPU statistics, including idle time and wait time. You can calculate the overall CPU utilization using the idle time using the formula given below:

CPU utilization = 100 - idle time

For example, in the output above, the idle time is 98.3%, so the CPU utilization can be calculated as follows:

CPU utilization = 100 - 98.3 = 1.7%

The top command generates a list of processes sorted by the parameter %CPU, or percentage of CPU consumed by a process. This list includes various details about each process and is refreshed automatically every 5 seconds.

mpstat Command

The mpstat command provides information about CPU performance and utilization by giving CPU statistics for the whole system and each available processor.

Running the mpstat command on a Linux system will display an output like the one shown in figure 2.

Understanding CPU utilization in Linux: Site24x7 (2) Fig 2: Output of mpstat command

This command shows various CPU statistics including idle time, io wait time and steal time. Similar to the top command, the idle time shown here can be used to compute the CPU utilization using the same formula.

The following command can be run to get statistics for each of the CPUs or processors:

mpstat -P ALL 

This command will generate an output similar to the one shown in figure 3.

Understanding CPU utilization in Linux: Site24x7 (3) Fig 3: Output of mpstat -p ALL command

Thus, the CPU utilization of processors CPU0 and CPU1 can be calculated as shown below:

CPU0 = 100 - 92.13 = 7.87

CPU1= 100 - 22.78 = 77.22

Monitoring CPU utilization per process

Checking the CPU utilization for each process is essential. A system may show high CPU utilization even though only a few processes account for most of the usage. Investigate individual processes to identify the cause and terminate them as needed.

In addition to top command, ps is another useful command for viewing process-level CPU statistics.

ps command

The ps command provides information about the processes running in the Linux system. It’s used to view process-related information, including the user of the process, the type of terminal used, and the PID of the process.

Running the ps command on a Linux system will generate an output similar to the one shown below.

Understanding CPU utilization in Linux: Site24x7 (4) Fig 4: Output of ps command

You can also use the ps command to view the top 10 most CPU-intensive processes by running the following command:

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 

The output of this command will look similar to the figure below.

Understanding CPU utilization in Linux: Site24x7 (5) Fig 5: Top 10 most CPU consuming processes

The output of the above command provides process-related information such as process ID(PID), process user, and the command used to run the process. This information is sorted according to CPU utilization and helps a user identify the process using most of the CPU so they can take action accordingly.

Conclusion

CPU utilization represents the amount of work a CPU handles to process resources or manage an operating system’s tasks. This metric is used to determine system performance by estimating the average CPU usage over a certain period of time.

Several factors contribute to high CPU usage so it’s essential to find the root cause to reduce it. This article provides three useful commands—top, mpstat, and ps to help users monitor and troubleshoot CPU related issues on Linux.

In most scenarios, these commands are sufficient to troubleshoot and reduce the high CPU utilization.

Was this article helpful?

Sorry to hear that. Let us know how we can improve the article.

Previous How to fix high CPU usage Next Understanding IOPS vs. throughput
Understanding CPU utilization in Linux: Site24x7 (2024)
Top Articles
Temporary or special motor vehicle permit
Working with the Analysis view in Business Central - Leading Software Company in Surat India
SZA: Weinen und töten und alles dazwischen
Ffxiv Act Plugin
Wordscapes Level 5130 Answers
Kaydengodly
Dr Lisa Jones Dvm Married
7543460065
J Prince Steps Over Takeoff
270 West Michigan residents receive expert driver’s license restoration advice at last major Road to Restoration Clinic of the year
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Tripadvisor Near Me
8 Ways to Make a Friend Feel Special on Valentine's Day
Moonshiner Tyler Wood Net Worth
Louisiana Sportsman Classifieds Guns
Log in or sign up to view
Whitefish Bay Calendar
Effingham Bookings Florence Sc
623-250-6295
Hennens Chattanooga Dress Code
Airrack hiring Associate Producer in Los Angeles, CA | LinkedIn
Gas Buddy Prices Near Me Zip Code
Bento - A link in bio, but rich and beautiful.
Coindraw App
Ardie From Something Was Wrong Podcast
Tactical Masters Price Guide
Amazing Lash Bay Colony
Best New England Boarding Schools
Current Time In Maryland
Tra.mypatients Folio
Http://N14.Ultipro.com
CVS Near Me | Somersworth, NH
Aveda Caramel Toner Formula
Buhsd Studentvue
Tiny Pains When Giving Blood Nyt Crossword
Hindilinks4U Bollywood Action Movies
Trivago Myrtle Beach Hotels
Crazy Balls 3D Racing . Online Games . BrightestGames.com
What Is Kik and Why Do Teenagers Love It?
Avance Primary Care Morrisville
Comanche Or Crow Crossword Clue
Ups Authorized Shipping Provider Price Photos
Reilly Auto Parts Store Hours
Bellelement.com Review: Real Store or A Scam? Read This
Dineren en overnachten in Boutique Hotel The Church in Arnhem - Priya Loves Food & Travel
Rubmaps H
Sml Wikia
Pilot Travel Center Portersville Photos
Home | General Store and Gas Station | Cressman's General Store | California
Denys Davydov - Wikitia
Bumgarner Funeral Home Troy Nc Obituaries
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 6457

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.