Viewing CPU load in Linux environment
In Linux, CPU consumption, sorted by the greatest load, can be viewed using two commands: ps and top.
Important tip: The value in the "CPU" column in both commands is counted based on the load of one processor core. Thus, the sum of percentages on multi-core machines will be more than 100%. E.g. for a quad-core processor, the total percentage of consumption for all processes may not exceed 400%.
Let's consider each of the commands in more detail.
'ps' command
To start it, enter the following command into the OS console:
ps -aux --sort -pcpu
Example command output:
$ ps -aux --sort -rss
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 30799 51.2 8.1 2733764 285136 ? Rl 09:25 5:30 /usr/lib/chromium-browser/chromium-browser --ppapi-flash-path=/usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so --ppap
user 2800 0.1 6.6 9972812 234184 ? Sl oct31 1:26 /usr/bin/plasmashell --shut-up
user 31308 2.4 5.3 1767496 188672 ? Sl 09:26 0:13 /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --field-trial-handle=7228759356551874141,180166971
user 31011 3.9 5.3 1793296 186812 ? Sl 09:25 0:25 /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --field-trial-handle=7228759356551874141,180166971
user 31369 5.5 4.8 1378568 171328 ? Sl 09:28 0:23 /usr/lib/libreoffice/program/soffice.bin --writer --splash-pipe=5
user 14442 12.1 4.2 1050808 150148 ? Sl 01:19 60:04 /usr/lib/x86_64-linux-gnu/libexec/kscreenlocker_greet --graceTime 5000 --ksldfd 26
user 31111 0.9 3.8 1708496 134564 ? Sl 09:25 0:06 /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --field-trial-handle=7228759356551874141,180166971
user 1225 0.0 3.7 3639148 132092 ? Sl oct31 1:00 /usr/bin/plasmashell --shut-up
user 31078 0.6 3.7 1724480 130724 ? Sl 09:25 0:03 /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --field-trial-handle=7228759356551874141,180166971
user 30986 0.7 3.3 1717860 117660 ? Sl 09:25 0:04 /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --field-trial-handle=7228759356551874141,180166971
user 1216 1.7 3.2 3271220 113736 ? Sl oct31 20:36 kwin_x11
Important columns are:
- USER The user on whose behalf the process is running
- PID Process ID
- %CPU CPU load percentage
This output makes it clear that an instance of the dd program with PID = 30799 completely utilizes half of one core of the processor.
'top' command
Also, the CPU load can be viewed interactively using the top command. To start it, enter the following command into the OS console:
top
Example command output:
top - 15:13:56 up 8 days, 5:18, 4 users, load average: 0,01, 0,04, 0,05
Tasks: 124 total, 1 running, 123 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0,0 us, 0,0 sy, 0,0 ni, 99,9 id, 0,1 wa, 0,0 hi, 0,0 si, 0,0 st
KiB Mem: 2060916 total, 1714780 used, 346136 free, 184580 buffers
KiB Swap: 901116 total, 0 used, 901116 free, 999472 cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
22684 root 20 0 24768 1476 1016 R 0,3 0,1 0:00.01 top
1 root 20 0 15444 756 612 S 0,0 0,0 0:08.79 init
2 root 20 0 0 0 0 S 0,0 0,0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0,0 0,0 1:08.03 ksoftirqd/0
5 root 20 0 0 0 0 S 0,0 0,0 0:00.00 kworker/u:0
6 root rt 0 0 0 0 S 0,0 0,0 0:00.77 migration/0
7 root rt 0 0 0 0 S 0,0 0,0 0:02.81 watchdog/0
8 root rt 0 0 0 0 S 0,0 0,0 0:00.77 migration/1
10 root 20 0 0 0 0 S 0,0 0,0 0:04.40 ksoftirqd/1
12 root rt 0 0 0 0 S 0,0 0,0 0:02.40 watchdog/1
13 root rt 0 0 0 0 S 0,0 0,0 0:01.50 migration/2
15 root 20 0 0 0 0 S 0,0 0,0 0:04.33 ksoftirqd/2
16 root rt 0 0 0 0 S 0,0 0,0 0:02.26 watchdog/2
17 root rt 0 0 0 0 S 0,0 0,0 0:00.49 migration/3
19 root 20 0 0 0 0 S 0,0 0,0 0:03.73 ksoftirqd/3
20 root rt 0 0 0 0 S 0,0 0,0 0:02.21 watchdog/3
21 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 cpuset
22 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 khelper
23 root 20 0 0 0 0 S 0,0 0,0 0:00.00 kdevtmpfs
24 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 netns
25 root 20 0 0 0 0 S 0,0 0,0 0:01.84 sync_supers
26 root 20 0 0 0 0 S 0,0 0,0 0:00.05 bdi-default
27 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 kintegrityd
28 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 kblockd
30 root 20 0 0 0 0 S 0,0 0,0 0:08.20 kworker/2:1
31 root 20 0 0 0 0 S 0,0 0,0 0:01.98 kworker/3:1
32 root 20 0 0 0 0 S 0,0 0,0 0:00.32 khungtaskd
33 root 20 0 0 0 0 S 0,0 0,0 0:00.00 kswapd0
34 root 25 5 0 0 0 S 0,0 0,0 0:00.00 ksmd
35 root 39 19 0 0 0 S 0,0 0,0 0:00.00 khugepaged
36 root 20 0 0 0 0 S 0,0 0,0 0:00.00 fsnotify_mark
37 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 crypto
103 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 ata_sff
111 root 20 0 0 0 0 S 0,0 0,0 0:00.00 scsi_eh_0
114 root 20 0 0 0 0 S 0,0 0,0 0:00.01 scsi_eh_1
115 root 20 0 0 0 0 S 0,0 0,0 0:15.02 kworker/u:1
119 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 mpt_poll_0
137 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 mpt/0
165 root 20 0 0 0 0 S 0,0 0,0 0:00.00 scsi_eh_2
169 root 20 0 0 0 0 S 0,0 0,0 0:11.68 kworker/3:2
177 root 20 0 0 0 0 S 0,0 0,0 1:37.28 kworker/1:2
207 root 20 0 0 0 0 S 0,0 0,0 0:07.77 flush-8:0
213 root 20 0 0 0 0 S 0,0 0,0 0:21.32 jbd2/sda1-8
214 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 ext4-dio-unwrit
355 root 20 0 24140 1468 816 S 0,0 0,1 0:00.06 udevd
502 root 20 0 24100 1096 468 S 0,0 0,1 0:00.00 udevd
503 root 20 0 24100 1028 408 S 0,0 0,0 0:00.00 udevd
527 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 kpsmoused
528 root 20 0 0 0 0 S 0,0 0,0 0:04.36 kworker/2:2
555 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 ttm_swap
1842 root 20 0 152m 8928 4548 S 0,0 0,4 8:15.13 vmtoolsd
1885 root 20 0 60288 9396 6444 S 0,0 0,5 0:00.04 VGAuthService
1979 root 20 0 199m 5016 4128 S 0,0 0,2 3:19.79 ManagementAgent
Important columns are:
- USER The user on whose behalf the process is running
- PID Process ID
- %CPU CPU load percentage
This output shows that no one of processes use more then 1% of the capabilities of one of the CPU cores.