How to Check Linux CPU Usage or Utilization (2024)

Monitoring the performance of the CPU is an essential task for any system administrator who needs to measure the performance of a system. This will help you to debug system processes, manage system resources, and make system decisions. There are several tools available for checking CPU usage in Linux.

In this post, we will demonstrate a few methods to check and monitor CPU usage in Linux. NOTE: This article assumes that your base system is updated with the latest available packages.

In This Article

  • Check CPU Usage with top Command
  • Check CPU Usage with mpstat Command
  • Check CPU Usage with sar Command
  • Check CPU Usage with iostat Command
  • Check CPU Usage with vmstat Command

1. Check CPU Usage with top Command

Top is a very useful command-line tool that helps you to monitor all running processes in real-time. It will display information about the readout of users, tasks, CPU load, and memory usage in real-time. By default, the top command updates the data every 5 seconds.

Now, let’s start using the top command to monitor the CPU usage:

top

You should see the all running processes on the following screen:
How to Check Linux CPU Usage or Utilization (1)
Type P to sort all running processes by CPU usage. You should see the following screen:
How to Check Linux CPU Usage or Utilization (2)
Type M to sort all running processes by Memory usage. You should see the following screen:
How to Check Linux CPU Usage or Utilization (3)
Type I to hide all idle processes. You should see the following screen:
How to Check Linux CPU Usage or Utilization (4)
Type S to sort all processes by how long the processes have been running:
How to Check Linux CPU Usage or Utilization (5)
Type U to view all processes owned by a specific user. You should see the following screen:
How to Check Linux CPU Usage or Utilization (6)

2. Check CPU Usage with mpstat Command

Mpstat is a part of the sysstat package.

For Debian or Ubuntu operating systems, you can install it using the following command:

apt-get install sysstat -y

For CentOS or RHEL operating systems, you can install it using the following command:

yum install sysstat -y

Now, run the mpstat command without any options. This will display usage for each processor:

mpstat

Sample output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)12:28:46 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12:28:46 IST all 18.30 0.01 3.44 8.26 0.00 0.16 0.00 0.00 0.00 69.82

To display a report for the first processor, run:

mpstat -P 0

Sample output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)12:29:35 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12:29:35 IST 0 18.16 0.01 3.94 8.68 0.00 0.27 0.00 0.00 0.00 68.93

To display the report of all processors, run:

mpstat -P ALL

Sample output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)12:45:50 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12:45:50 IST all 16.38 0.01 3.11 7.33 0.00 0.15 0.00 0.00 0.00 73.0212:45:50 IST 0 16.28 0.01 3.58 7.76 0.00 0.25 0.00 0.00 0.00 72.1212:45:50 IST 1 16.25 0.01 3.06 7.10 0.00 0.05 0.00 0.00 0.00 73.5212:45:50 IST 2 16.38 0.01 2.87 7.39 0.00 0.24 0.00 0.00 0.00 73.1112:45:50 IST 3 16.60 0.01 2.93 7.07 0.00 0.06 0.00 0.00 0.00 73.34

To display average CPU usage for 3 times at 2-second intervals:

mpstat -P ALL 2 3

Sample output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)12:47:58 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12:48:00 IST all 23.30 0.00 4.99 4.74 0.00 0.00 0.00 0.00 0.00 66.9712:48:00 IST 0 29.02 0.00 5.18 6.74 0.00 0.00 0.00 0.00 0.00 59.0712:48:00 IST 1 26.53 0.00 6.12 4.59 0.00 0.51 0.00 0.00 0.00 62.2412:48:00 IST 2 22.96 0.00 3.57 2.04 0.00 0.00 0.00 0.00 0.00 71.4312:48:00 IST 3 14.14 0.00 5.05 5.56 0.00 0.00 0.00 0.00 0.00 75.2512:48:00 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12:48:02 IST all 21.58 0.00 5.87 5.11 0.00 0.13 0.00 0.00 0.00 67.3112:48:02 IST 0 25.13 0.00 9.23 9.23 0.00 0.51 0.00 0.00 0.00 55.9012:48:02 IST 1 28.72 0.00 7.18 8.21 0.00 0.00 0.00 0.00 0.00 55.9012:48:02 IST 2 18.88 0.00 3.06 1.53 0.00 0.00 0.00 0.00 0.00 76.5312:48:02 IST 3 13.85 0.00 4.10 1.03 0.00 0.00 0.00 0.00 0.00 81.0312:48:02 IST CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12:48:04 IST all 24.78 0.00 5.11 5.87 0.00 0.13 0.00 0.00 0.00 64.1112:48:04 IST 0 30.37 0.00 3.66 10.47 0.00 0.00 0.00 0.00 0.00 55.5012:48:04 IST 1 27.78 0.00 6.06 9.09 0.00 0.00 0.00 0.00 0.00 57.0712:48:04 IST 2 23.23 0.00 5.56 1.01 0.00 0.00 0.00 0.00 0.00 70.2012:48:04 IST 3 17.86 0.00 5.10 3.57 0.00 0.51 0.00 0.00 0.00 72.96Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idleAverage: all 23.22 0.00 5.33 5.24 0.00 0.09 0.00 0.00 0.00 66.13Average: 0 28.15 0.00 6.04 8.81 0.00 0.17 0.00 0.00 0.00 56.82Average: 1 27.67 0.00 6.45 7.30 0.00 0.17 0.00 0.00 0.00 58.40Average: 2 21.69 0.00 4.07 1.53 0.00 0.00 0.00 0.00 0.00 72.71Average: 3 15.28 0.00 4.75 3.40 0.00 0.17 0.00 0.00 0.00 76.40

3. Check CPU Usage with sar Command

The sar command is also used for collecting and reporting system activity information.

You can use the sar command with the -u option to track CPU performance. The following command will display CPU usage every 2 seconds.

sar -u 2

Sample output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)12:53:26 IST CPU %user %nice %system %iowait %steal %idle12:53:28 IST all 5.30 0.00 2.02 2.52 0.00 90.1612:53:30 IST all 2.90 0.00 1.39 1.13 0.00 94.5812:53:32 IST all 3.57 0.00 2.04 0.76 0.00 93.63

The above command will run indefinitely. You can stop it using CTRL+C.

4. Check CPU Usage with iostat Command

The iostat displays information on device utilization and the system’s average CPU utilization since the last reboot.

Run the iostat command without any option will display the information about CPU utilization, device utilization, and network file system utilization.

iostat

You should see the following output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)avg-cpu: %user %nice %system %iowait %steal %idle 16.41 0.01 3.31 6.83 0.00 73.44Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtnloop0 0.01 0.04 0.00 373 0loop1 0.01 0.04 0.00 387 0loop2 2.59 2.62 0.00 23279 0loop3 0.00 0.01 0.00 116 0loop4 0.01 0.02 0.00 143 0loop5 28.67 28.70 0.00 255344 0loop6 0.01 0.04 0.00 385 0loop7 0.00 0.01 0.00 121 0sda 34.36 383.67 600.72 3413776 5345096

Use the -c option to break the CPU utilization into user processes, system processes, I/O wait, and idle time.

iostat -c

Sample output:

Linux 4.4.0-148-generic (newpc) Monday 23 August 2021 _x86_64_(4 CPU)avg-cpu: %user %nice %system %iowait %steal %idle 16.40 0.01 3.31 6.82 0.00 73.46

5. Check CPU Usage with vmstat Command

The vmstat command will display the information about system processes, memory, swap, I/O, and CPU performance. It will display the average details since the last reboot.

Run the vmstat command without any options as shown below:

vmstat

Sample output:

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 3 1 1028672 130972 124344 1212276 19 71 101 150 341 818 17 3 73 7 0

The following command will update vmstat report every 2 seconds:

vmstat 2

Sample output:

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 1 1032572 233396 125196 1129256 19 70 100 149 345 830 17 3 73 7 0 2 0 1032572 232976 125212 1129596 0 0 0 112 3051 8697 40 10 42 8 0 0 1 1032572 233040 125224 1130468 0 0 0 1510 3109 8631 43 9 41 8 0

Press CTRL+C to close the vmstat.

Conclusion

In the above guide, we explained different methods to check CPU usage in Linux. These tools can help you to track processor usage and the performance of your system. Give it a try today on your VPS from Altantic.Net.

How to Check Linux CPU Usage or Utilization (2024)

FAQs

How to Check Linux CPU Usage or Utilization? ›

You can check how your CPU is being used with the htop command. This prints out real-time information that includes tasks, threads, load average uptime and usage for each CPU. You should see a real-time display with information on how your CPU is being put to use.

How do I check CPU usage or utilization in Linux? ›

You can check how your CPU is being used with the htop command. This prints out real-time information that includes tasks, threads, load average uptime and usage for each CPU. You should see a real-time display with information on how your CPU is being put to use.

How to check CPU utilization? ›

Using the Task Manager: Open the Task Manager (Ctrl + Shift + Esc) and go to the “Performance” tab. The CPU usage will display as a graph; if the computer runs high CPU usage, the chart will be primarily red.

How to check CPU utilization in Linux using SAR? ›

The command has the following variations: sar -u : Displays CPU usage for the current day. sar -u 1 3 : Displays real-time CPU usage every 1 second for 3 times. sar -u ALL : Same as the sar -u command, but displays additional fields.

How do I know which process is taking more memory in Linux? ›

Using the /proc/meminfo File

There are several ways to check which application is using the maximum memory in Linux. Whether you use the top , htop , ps , free , or /proc/meminfo command, understanding your system's memory usage can be helpful in identifying performance issues and finding ways to optimize your system.

How to check CPU utilization in Unix command? ›

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).

Which command is used to check CPU utilization in Linux? ›

Use the sar -u command to display CPU utilization statistics. The sar command without any options is equivalent to sar -u . At any given moment, the processor is either busy or idle.

How to check CPU count in Linux? ›

How to check how many CPUs are there in the Linux system
  1. lscpu command. The lscpu command is the primary utility that displays CPU details such as CPU op-mode, vendor id, model name, CPU family, etc. ...
  2. 2. /proc/cpuinfo. ...
  3. nproc command. ...
  4. top or htop command. ...
  5. hwinfo. ...
  6. dmidecode command. ...
  7. getconf _NPROCESSORS_ONLN command.
Jan 2, 2023

How to check CPUs in Linux? ›

The command-line utility “lscpu” in Linux is used to get CPU information of the system. The “lscpu” command fetches the CPU architecture information from the “sysfs” and /proc/cpuinfo files and displays it in a terminal.

How to reduce CPU utilization in Linux? ›

The first thing to do when the CPU becomes overloaded is to identify any processes of this kind and terminate or restart them. Update system apps and drivers: Outdated drivers and apps can also cause high CPU load because they can't effectively perform the I/O operations.

How do I monitor system performance in Linux? ›

Linux System Monitoring Commands & Tools
  1. System Activity and Running Process & Their Up-time.
  2. Checking System Activity using vmstat Command.
  3. System's available Space and Cache Using free Command.
  4. Disk Performance and Activity using iostat Command.
  5. Network Connections, Open Ports, Packets & Protocols using netstat Command.
Jan 17, 2024

How to check CPU power consumption in Linux? ›

Let's look at some additional utilities that provide detailed information on the battery status and other sensor information.
  1. 3.1. Using lm_sensors. The lm_sensors application comes with the sensors command, which we can use to get the battery information. ...
  2. 3.2. Using tlp-stat. ...
  3. 3.3. Using powerstat. ...
  4. 3.4. powertop.
Mar 18, 2024

How do I monitor resources in Linux? ›

How to Check Memory Usage in Linux via CLI and GUI
  1. Check Memory Usage in Linux via Command Line. cat Command. free Command. vmstat Command. top Command. htop Command. sar Command. /proc/meminfo.
  2. Check Memory Usage in Linux via GUI.
Mar 28, 2024

What is the command to check CPU and memory utilization in Linux? ›

CPU utilization
  1. Top. It provides real-time information about system performance, including CPU and memory utilization. ...
  2. mpstat. This command displays CPU usage statistics. ...
  3. sar. This command collects, reports, and saves system activity information, including CPU and memory usage. ...
  4. iostat. ...
  5. vmstat. ...
  6. free. ...
  7. df. ...
  8. du.
Sep 13, 2023

How to check memory utilization in Linux? ›

The most common way you'll see on the web to check for free memory in Linux is by using the free command. Using the free -m command to check your Linux memory usage, displays the values as MB instead of KB.

How do I find top 10 CPU consuming processes in Linux? ›

Use the top Command to Find Top Processes by Memory and CPU Usage. top is another built-in Linux command-line utility that can be used to show all running processes in Linux. You can use various options with the top command to filter the output based on your requirements.

How to check resource utilization on Linux? ›

The pidstat Command. Linux offers another command named pidstat to check the percentage of resources being used. However, it only gives us a snapshot of current resource usage when we run this command, rather than providing a real-time view as we can expect from the top command.

How to check disk utilization in Linux? ›

The df command stands for "disk-free," and shows available and used disk space on the Linux system. df -T shows the disk usage along with each block's filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.) You can get this information in a graphical view using the Disks (gnome-disk-utility) in the GNOME desktop.

Top Articles
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 6212

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.