Monitoring CPU usage is crucial in Linux, especially when managing system performance or diagnosing issues. CPU usage information helps users understand how system resources are being allocated and identify processes that may be consuming excessive CPU time. This data is essential for optimizing performance and ensuring that the system runs efficiently.
There are several tools available in Linux to display CPU usage information. Some of the most commonly used tools include top, htop, mpstat, sar, and vmstat. Each of these tools provides real-time insights into CPU usage, allowing users to monitor system performance and adjust resource allocation as needed.
This article will guide you through the steps to display CPU usage information on a Linux system using top, htop, mpstat, sar, and vmstat. Each method is accompanied by a brief introduction to the tool, explaining its specific use case and advantages.
Steps to display CPU usage information using top:
Top is one of the most commonly used tools for monitoring system performance in Linux. It provides a real-time view of all running processes, showing their CPU usage, memory usage, and other critical information. The simplicity and accessibility of top make it a go-to tool for quickly assessing system load and identifying resource-hungry processes.
One of the key advantages of top is its ability to provide an instant snapshot of system activity, which is especially useful when troubleshooting performance issues. It allows users to sort processes by CPU usage, making it easy to identify which processes are consuming the most resources.
- Open the terminal and run the top command.
$ top
The top command provides a real-time overview of system processes, including CPU usage, memory usage, and process IDs. The CPU usage for each process is displayed in the %CPU column.
- Press q to exit the top command interface.
Use the top command to monitor CPU usage over time. It is particularly useful for identifying processes that are consuming a high percentage of CPU resources.
Steps to display CPU usage information using htop:
Htop is an enhanced version of top, offering a more user-friendly and interactive interface. It provides the same real-time monitoring features as top but with additional functionalities such as scrolling, process tree view, and color-coded displays. These enhancements make htop more visually appealing and easier to navigate, especially for users who prefer a graphical interface.
Htop is particularly useful for managing processes directly from the interface. Users can kill processes, change their priorities, and sort them by various criteria, all within the htop interface. This makes htop a powerful tool for both monitoring and managing system resources.
- Install the htop package if it is not already installed.
$ sudo apt update && sudo apt install htop //Ubuntu and derivatives// $ sudo zypper refresh && sudo zypper install htop //openSUSE// $ sudo dnf install htop //Fedora and RHEL//
Htop is a more user-friendly version of top, offering an interactive interface with additional features for monitoring system resources.
- Run the htop command in the terminal.
$ htop
Htop provides a real-time visual representation of CPU usage, memory usage, and other system resources. The interface allows you to scroll through the list of processes and sort them by CPU usage, memory usage, and other criteria.
- Use the arrow keys to navigate, and press F10 to exit.
Htop is particularly useful for users who prefer a graphical interface to monitor system performance. It also allows you to manage processes directly from the interface.
Steps to display CPU usage information using mpstat:
Mpstat is part of the sysstat package and provides detailed CPU usage statistics, including usage per CPU core. Unlike top and htop, which focus on individual processes, mpstat offers a more granular view of how CPU resources are being used across the entire system. It reports statistics for user time, system time, idle time, and other critical metrics, making it ideal for performance analysis.
One of the key benefits of mpstat is its ability to provide CPU usage statistics over time. By running mpstat with intervals and counts, users can monitor how CPU usage evolves, which is particularly useful for diagnosing intermittent performance issues or understanding long-term resource consumption patterns.
- Install the sysstat package if it is not already installed.
$ sudo apt update && sudo apt install sysstat //Ubuntu and derivatives// $ sudo zypper refresh && sudo zypper install sysstat //openSUSE// $ sudo dnf install sysstat //Fedora and RHEL//
Mpstat is part of the sysstat package, which includes a collection of performance monitoring tools. Mpstat provides detailed CPU usage statistics, including usage per CPU core.
- Run the mpstat command to display CPU usage information.
$ mpstat Linux 5.4.0-74-generic (hostname) 08/28/2024 _x86_64_ (4 CPU) 12:00:00 CPU %usr %nice %sys %iowait %irq %soft %steal %idle %guest 12:00:00 all 3.20 0.00 2.10 0.10 0.00 0.30 0.00 94.30 0.00
The mpstat command provides a snapshot of CPU usage statistics for all CPU cores. The columns represent different aspects of CPU usage, including user processes (%usr), system processes (%sys), and idle time (%idle).
- Run mpstat with an interval and count to monitor CPU usage over time.
$ mpstat 2 5
The command mpstat 2 5 will display CPU usage information every 2 seconds for 5 iterations, providing a real-time view of CPU performance.
Steps to display CPU usage information using sar:
Sar is another tool in the sysstat package, and it specializes in collecting, reporting, and saving system activity information. Unlike the previous tools that focus on real-time monitoring, sar excels at providing historical data about CPU usage, which is invaluable for long-term performance analysis and capacity planning.
One of the strengths of sar is its ability to generate reports on CPU usage over days, weeks, or even months. This makes sar particularly useful for identifying trends, understanding resource consumption patterns, and making informed decisions about system upgrades or configuration changes.
- Install the sysstat package if it is not already installed.
$ sudo apt update && sudo apt install sysstat //Ubuntu and derivatives// $ sudo zypper refresh && sudo zypper install sysstat //openSUSE// $ sudo dnf install sysstat //Fedora and RHEL//
Sar is another tool in the sysstat package that collects, reports, and saves system activity information. It can provide detailed historical data about CPU usage over time.
- Run the sar command to display CPU usage information.
$ sar -u 1 5 Linux 5.4.0-74-generic (hostname) 08/28/2024 _x86_64_ (4 CPU) 12:00:00 CPU %user %nice %system %iowait %steal %idle 12:00:01 all 3.20 0.00 2.10 0.10 0.00 94.60 12:00:02 all 3.00 0.00 1.80 0.00 0.00 95.20 12:00:03 all 2.50 0.00 2.00 0.00 0.00 95.50 12:00:04 all 2.80 0.00 1.90 0.00 0.00 95.30 12:00:05 all 2.90 0.00 2.10 0.00 0.00 95.00
The sar -u 1 5 command displays CPU usage statistics every 1 second for 5 iterations. The columns show the percentage of time the CPU spends on different tasks, including user processes, system processes, and idle time.
- Use sar to save historical data and analyze CPU usage trends.
Sar is particularly useful for long-term monitoring and performance analysis. It can help identify trends in CPU usage over days, weeks, or months.
Steps to display CPU usage information using vmstat:
Vmstat provides a broader overview of system performance, including CPU usage, memory usage, and I/O activity. It is particularly useful for identifying system bottlenecks, as it displays information about processes, memory, paging, block I/O, traps, and CPU activity in a single output. Vmstat is a powerful tool for users who need a comprehensive view of system performance.
Vmstat is also valuable for monitoring CPU usage over time. By running vmstat with intervals, users can track how CPU, memory, and I/O usage change in real-time, helping to diagnose performance issues and optimize system resources effectively.
- Run the vmstat command to display CPU usage and other system performance information.
$ vmstat 2 5 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 500000 60000 300000 0 0 0 0 100 200 3 1 96 0 0 0 0 0 499000 61000 300500 0 0 0 0 105 205 2 1 97 0 0 0 0 0 498000 62000 301000 0 0 0 0 110 210 1 1 98 0 0 0 0 0 497000 63000 301500 0 0 0 0 115 215 3 2 95 0 0 0 0 0 496000 64000 302000 0 0 0 0 120 220 4 1 95 0 0
The vmstat command provides information about processes, memory, swap, I/O, and CPU performance. The columns under the cpu section display user time (us), system time (sy), idle time (id), and wait time (wa).
- Use vmstat to monitor overall system performance, including CPU usage.
Vmstat is useful for a quick overview of system performance, helping to identify bottlenecks in CPU, memory, or I/O usage.

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.