Analyzing CPU usage is very important for the smooth running of any system. Sometimes CPU usage reaches 100% and due to that CPU becomes unavailable for processing other requests until the CPU becomes free. There may be multiple reasons behind high CPU usage, such as Programs with higher CPU requirements, autostart programs, multiple opened tabs of browsers, and many more reasons. In this tutorial, I am going to explain how to check CPU usage in Linux and the causes of high CPU usage in Linux. So, let’s get started.
How to Check CPU Usage in Linux
There are plenty of tools and commands to monitor CPU Usage. Let’s start with the most popular command top to find out CPU usage in Linux. In this article, I am going to discuss commonly used methods to check CPU usage.
Top command (Most common method)
The top command provides a real-time view of the system. It displays CPU utilization, process statistics, threads details, uptime, swap space, etc. All the data are filterable by size, type, and order.
Open terminal from the application launcher or press (control + alt + t) on the keyboard. Now, run the
The top command will show all the running processes, threads, system uptime, number of users, the total number of running tasks, etc. To exit from
top, press Q on the keyboard.
Sample output of top command.
Now let’s see how we can check the information one by one by sorting the
top command with options.
Some Important Top Command Options to Check CPU Usage
|P||Sort processes by CPU usage|
|I||Remove idle processes|
|S||Sort the list by how long processes have been running|
|M||sort task list by memory usage|
|T||sort task list by run time|
|N||sort task list by process id|
To access the help manual of the top command, run following command.
$ man top
Check CPU Usage using htop
Htop is more like an improved version of top command with more interactive, graphical, and easier to read than top command. Htop allows you to kill the processes without PID, it makes it easier to sort the process based on the usage, etc. To install htop on the Ubuntu system, run the following command.
$ sudo apt install htop
Once the installation completed. Run the htop command.
Learn more about htop here.
CPU Activity Check using mpstat Command
The mpstat command writes to standard output activities for each available processor. Most of the RHEL based operating systems include mpstat by default. In Ubuntu, you need to install sysstat to use mpstat. Run the following command to install sysstat.
$ sudo apt install sysstat
Once the installation is completed, run mpstat command to check the CPU activity details.
You should get the following output.
To print from the first processor (0 is the first one) with option -p and ALL will list all the CPU statistics. The command is
$ mpstat -P ALL
In this article, you have learned how to check CPU usage in Linux. If you have any doubts feel free to contact me, I will definitely try to help you. Also, you can join our elite facebook group to get direct help from me. If you like this tutorial, please share this article on your social media handle.