How to Check Linux CPU Usage or Utilization? {Easy Way} (2024)

Introduction

Understanding CPU processor usage is important for overall system-performance measurement. From Linux enthusiasts to system admins, knowing how to monitor CPU utilization in Linux from the command line is crucial.

This guide will walk you through several options to check Linux CPU usage.

How to Check Linux CPU Usage or Utilization? {Easy Way} (1)

Prerequisites

  • A Linux-based computer (e.g., Ubuntu and CentOS)
  • Access to a user account withsudoprivileges
  • A command prompt (Ctrl-Alt-T in Ubuntu, Menu > Applications > Utilities > Terminal in CentOS)
  • (optional) A package installer, likeaptoryum, usually included by default

Note: Use one of 5 available commands in Linux to check memory usage.

How To Check CPU Usage from Linux Command Line

top Command to View Linux CPU Load

Open a terminal window and enter the following:

top

The system should respond by displaying a list of all the processes that are currently running. It will also give a readout of users, tasks, CPU load, and memory usage.

This list can frequently change, as background tasks start and complete. One helpful switch is to launch topwith the –i switch:

top –i

This hides all the idle processes, making it easier to sort through the list.

To quit thetopfunction, press the letterqon your keyboard.

Some other useful commands whiletopis running include:

  • M– sort task list by memory usage
  • P– sort task list by processor usage
  • N– sort task list by process ID
  • T– sort task list by run time

To get assistance withtop, you can press the letterhwhile it’s running.Or, you can enter the following at a command line:

man top

This will display the manual page for thetopcommand.

mpstat Command to Display CPU Activity

Mpstat is part of a software bundle calledsysstat. Most RHEL-based distributions include this software package.

For Debian and Ubuntu systems, you’ll need to install the sysstatpackage.

In a terminal window, enter the following:

sudo apt-get install sysstat

Allow the process to complete.

If you’re running an older (4.x or older) version of CentOS or Red Hat derivative, you can useup2dateto installsysstat:

sudo up2date install sysstat

For newer (5.x and later) installations of CentOS or Red Hat,sysstat can be installed using the following command:

sudo yum install sysstat

Once the process finishes, you can use thempstatcommand in the terminal as follows:

mpstat

The system will display usage for each processor (or processor core).

The first line is a set of column labels. The second line is the value for each column:

  • %usr – % CPU usage at the user level
  • %nice – % CPU usage for user processes labeled “nice”
  • %sys – % CPU usage at the system (Linux kernel) level
  • %iowait – % CPU usage idling waiting on a disk read/write
  • %irq – % CPU usage handling hardware interrupts
  • %soft – % CPU usage handing software interrupts
  • %steal – % CPU usage being forced to wait for a hypervisor handling other virtual processors
  • %guest – % CPU usage spent running a virtual processor
  • %idle – % CPU usage on idle time (no processes, and not waiting on a disk read/write)

You can add switches to thempstatcommand.

The –P switch allows you to specify a single processor to report:

mpstat –P 0

This would show you a report for the first processor (CPU 0).

mpstat –P ALL

This command would show you the total, like the basicmpstatcommand. It will also list processes by individual CPU.

Thempstatcommand only takes a snapshot of CPU usage.

To take a series of snapshots, use a number to indicate an interval and a second number to indicate the number of reports:

mpstat 5 7

This example would generate 7 snapshots, each 5 seconds apart.

sar Command to Show CPU Utilization

Thesar tool is a utility for managing system resources. It’s not limited strictly to CPU usage, but you can use the-uoption to track CPU performance.

Use the following command to directsarto monitor CPU usage at set intervals:

sar –u 5

The –u option tells it to display CPU usage. The 5 indicates that it should display every 5 seconds. This will run indefinitely. To cancel, press Ctrl-C.

iostat Command for Average Usage

In a terminal, enter the following:

iostat

The system will display average CPU usage since the last boot.It will also display input/output load (disk read/write activity).

More information oniostatcan be found on theLinux Manual pages.

Other Options to Monitor CPU Performance

Nmon Monitoring Tool

Nmon is a monitoring tool developed by Nigel Griffiths of IBM. To install Nmon on Ubuntu, enter the following:

sudo apt-get install nmon

To install to CentOS, enter the following:

sudo yum epel-release
sudo yum install nmon

The command to launchnmonis:

nmon

This will launch the utility, and display all the options. To view CPU usage, press the letterc. To switch back, presscagain.For a list of commands, pressh.To quit, pressq.

Graphical Utility Option

Many server systems don’t waste processor cycles on a graphical user interface (GUI).

However, you may have a lightweight GUI, or you may be using a client Linux system. Some versions, like Ubuntu, have a built-in graphical monitoring tool.

To launch Ubuntu’s system monitor, enter the following in a terminal window:

gnome-system-monitor

This starts a task-manager-like application where you can monitor tasks and CPU usage.

Typically, GUI’s have a “task manager” or “system monitor” application. This can be used to monitor CPU usage in real-time.

Conclusion

There are many different methods to check CPU usage in Linux.

This guide outlines the primary methods using built-in Linux tools or third-party applications. These commands will help you track processor usage and performance of your system, giving you greater control.

How to Check Linux CPU Usage or Utilization? {Easy Way} (2024)
Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 6302

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.