Knowledgebase

How to Check CPU Usage in Linux?

Ever felt like your Linux server is running slower than usual, or some applications are taking forever to respond?

Before blaming your hardware, it’s a good idea to check what’s really going on under the hood.

Your CPU, the brain of your computer or server, might be juggling too many tasks at once. Monitoring CPU usage in Linux isn’t just for tech experts; it’s for anyone who wants a smooth and responsive server.

In this guide, we will explore simple, practical ways to see what’s eating up your CPU, identify which processes are heavy, and keep your server running like a well-oiled machine.

No complicated jargon, just easy-to-follow steps that anyone can use!


Also Read: How to Check OS Version in Linux​?


Understanding CPU Usage

Before we dive into commands, let’s quickly understand what CPU usage means. CPU (Central Processing Unit) usage tells you how much of your server’s processing power is being used at a given time. Linux servers can run multiple processes simultaneously, and monitoring CPU usage helps you:

  • Identify resource-heavy processes.
  • Troubleshoot slow server performance.
  • Optimize server and application performance.

Now, let’s see how to check CPU usage in Linux!


Also Read: How to Check OS Kernel Version in Linux​?


Ways to Check CPU Usage in Linux

1. Using the top Command

The top command is one of the most common ways to monitor CPU usage in real-time.

Steps:

➔ Open your terminal.

➔ You have to type top and press Enter.

➔ You’ll see a list of running processes along with CPU usage details. Look for the %CPU column to see which processes are consuming the most CPU.

top Command use in linux
Tip: Press q to exit the top command when you’re done.

2. Using the htop Command

htop is similar to top but offers a more user-friendly interface with color-coded graphs.

Steps:

Install htop if it’s not already installed:

# For Debian/Ubuntu

Copied!
sudo apt install htop

# For CentOS/RHEL

Copied!
sudo yum install htop

➔ Type htop in the terminal and press Enter.

➔ You will see CPU usage represented in bars at the top. It’s easy to identify which processes are taking up more CPU.

htop Command use in linux
Tip: Use the arrow keys to navigate and F10 to exit.

3. Using the mpstat Command

The mpstat command is part of the sysstat package and shows CPU usage per processor/core.

Steps:

➔ You have to install sysstat if needed:

# For Debian/Ubuntu

Copied!
sudo apt install sysstat

# For CentOS/RHEL

Copied!
sudo yum install sysstat

➔ Type mpstat and press Enter.

➔ You will see statistics such as user CPU usage, server usage, and idle time.

mpstat Command use in linux
Tip: To get continuous updates every 2 seconds, use: mpstat 2


Also Read: How to Restart/Reboot Linux Server by Command?


4. Using the vmstat Command

vmstat provides an overview of server performance, including CPU usage.

Steps:

➔ Open the terminal.

➔ Type vmstat 2 5 and press Enter.

vmstat Command in linux

Here, 2 is the interval in seconds, and 5 is the number of reports.

➔ Check the us, sy, and id columns for CPU usage details:

  • us – CPU time spent on user processes
  • sy – CPU time spent on server processes
  • id – CPU idle time

5. Using the iostat Command

iostat is another tool from the sysstat package that gives CPU usage along with disk I/O stats.

Steps:

➔ Install sysstat if not already installed.

➔ Run the command:

Copied!
iostat -c

➔ You will see a summary of CPU usage, including user, server, idle, and wait times.

iostat Command use in  linux

6. Using the ps Command

If you want to check CPU usage for a specific process, ps is very handy.

Steps:

➔ Open the terminal.

➔ You have to run the command:

Copied!
ps -eo pid,ppid,cmd,%cpu,%mem –sort=-%cpu | head

➔ This will show the top CPU-consuming processes, along with their memory usage.

Top CPU-consuming processes


Also Read: How to Configure DNS on Linux?


Tips to Manage High CPU Usage

  •  Identify and stop unnecessary processes.
  •  Restart services that are misbehaving.
  •  Consider upgrading hardware for consistent high usage.
  •  Use scheduling tools like nice or cpulimit to manage resource-heavy tasks.


Also Read: How to Install Plesk on a Linux Server?


Conclusion

Monitoring CPU usage in Linux is simple once you know the right tools. Commands like top, htop, mpstat, and vmstat help you monitor your server’s performance and identify issues early. Whether you’re a beginner or a sysadmin, these tools are essential for maintaining a healthy Linux server.

Regularly checking CPU usage can help prevent performance bottlenecks and ensure your server runs smoothly.