FAQ: How to find out CPU load in Linux?

It’s rather trivial task to get information about how much of CPU time is consumed by Linux operating system, its components or various software it runs, but thankfully there are numerous utilities making it possible to get it. Some of them are included into certain Linux distribution, other aren’t but most of tools listed below can be used to find out CPU utilization statistics:

1. top

top is very old and important core utility coming with almost any Linux and Unix operating systems. It shows real-time system resources utilization (CPU, RAM, swap file etc.) to administrators via console, here is the part of it’s output:

top - 16:05:38 up 3 days,  6:08,  2 users,  load average: 0.54, 0.54, 0.61
Tasks: 100 total,   2 running,  98 sleeping,   0 stopped,   0 zombie
Cpu(s):  5.3%us,  1.0%sy,  0.0%ni, 93.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    515984k total,   497928k used,    18056k free,    13988k buffers
Swap:  1502068k total,    92956k used,  1409112k free,   129096k cached

As this tool provides a lot of useful information, it makes sense to read its manual page: type man top.

2. atsar

sar, atsar are other old tools providing system activity reports including CPU load we need. Here is an example of sar’s usage:

viper@viper-desktop:~$ sar -u 2 5
Linux  viper-desktop  2.6.20-17-generic  #2 SMP Mon Jun 9 22:08:13 UTC 2008  i686  07/04/2008
16:13:58  cpu %usr %nice   %sys %irq %softirq    %wait %idle             _cpu_
16:14:00  all    3     0      0    0        0        1    97
16:14:02  all    0     0      0    0        0        0    99
16:14:04  all    0     0      0    0        0        0   100
16:14:06  all   23     0      0    0        0        0    76
16:14:08  all    0     0      0    0        0        0   100

As you might see CPU utilization was almost 0% for two seconds after the command was executed. BTW, here is the description of the options sar was started with:

-u showed statistics about CPU utilization (average and per cpu) with 5 intervals of 2 seconds.

3. ps

ps is one the most used core utilities every Linux or Unix administrator uses as this utility with short name shows processes run in the system. If you need to get information about how much CPU or RAM resources are consumed by certain process, just run this:

viper@viper-desktop:~$ ps u 23988
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
viper 23988 0.0 0.6 5760 3280 pts/0 Ss 15:54 0:00 bash

where 23988 is PID of the process (can be get from the output of ps ax).

Of course it makes sense to read manuals of above mentioned commands ps, top, sar, atsar, iostat. Good luck!

SHARE:
nv-author-image

Stefan Durand

My name is Stefan, I'm the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *