How to Find CPU utilization in Linux

Leave a Comment
Hope, you must have checked CPU utilization on your Windows PC via task manager , also windows 7 and above have widget for the same. But what about Linux? Well , Linux have several ways by which we can easily determine CPU utilization , Utilization per processor , Average utilization and determining which process is  consuming maximum CPU(s)  etc.

1. Top:

Top is used for real time monitoring of processor activity so that we can take a look at the machine stats and  optimize the same.It displays complete system information and by default displays the processes in the order of CPU usage. While top command is running , Press M  in upper case to sort the memory usage.

The screenshot below shows the Output of Top command:



We get different type of information in the different columns:


  1. PID: Process I.D
  2. User : Owner of particular processs
  3. PR : Priority
  4. NI : Nice value  of process
  5. VIRT : Virtual memory used by the process
  6. RES : physical memory used from the process
  7. SHR:  Shared memory of the process
  8. S: Shows the status of the process , S= Sleep , Z= Zombie , R= Running
  9. %CPU : Percentage of CPU used by a particular process
  10. %MEM : Percentage of RAM used by the process
  11. TIME+  : Total  time of the activity of this process.
  12. COMMAND : Name of the process
2. Sar Command:

Sar command is very useful tool to determine CPU Utilization. 

Syntax:
$ sar -u 2 5 

 Screenshot credit


The above command will show the CPU utilization of Linux machine at interval of 2 seconds , 5 times.

3. mpstat :

Mpstat is used to check per processor stats. For using mpstat , you have to install a package called sysstat

#  mpstat  10 4

Above command will shows statistics 10 seconds apart , 4 times.

For monitoring  individual CPU performance, 

$  mpstat  -P ALL


4.  iostat :

For using iostat , you need package called  sysstat.
Command :  iostat -c 2
The above syntax will monitor CPU usage , -c is for cpu load and 2 is the time interval in seconds between reports.




 

0 comments:

Post a Comment