Linux проверить загрузку процессора

How can I determine the current CPU utilization from the shell? [closed]

How can I determine the current CPU utilization from the shell in Linux? For example, I get the load average like so:

Just FYI, the load average is not the CPU usage although it may indirectly show the CPU usage. It’s a number showing how many processes are out there running but waiting for resources, be it CPU or disk or something else.

can’t answer the question cause it’s closed but have a look at vmstat , as a bonus it works on BSDs as well.

7 Answers 7

Linux does not have any system variables that give the current CPU utilization. Instead, you have to read /proc/stat several times: each column in the cpu(n) lines gives the total CPU time, and you have to take subsequent readings of it to get percentages. See this document to find out what the various columns mean.

Because Space’s answer doesn’t work. It returns the average CPU usage since process start and not the current CPU usage. This answer is the correct one.

You can use top or ps commands to check the CPU usage.

using top : This will show you the cpu stats

using ps: This will show you the % cpu usage for each process.

ps -eo pcpu,pid,user,args | sort -r -k1 | less 

Also, you can write a small script in bash or perl to read /proc/stat and calculate the CPU usage.

We tried, and «top -b -n 1» gives very inaccurate results. «top»‘s first iteration is very approximative, can give 10 percent instead of 60.

top’s calculation of %CPU is different from ps’s calc of %CPU. see this answer unix.stackexchange.com/questions/58539/…

The command uptime gives you load averages for the past 1, 5, and 15 minutes.

Unfortunately I need it to exit right away so I can parse the output. I’m hoping there is a file in /proc that I can read.

This will be something like this:

cpu 55366 271 17283 75381807 22953 13468 94542 0 cpu0 3374 0 2187 9462432 1393 2 665 0 cpu1 2074 12 1314 9459589 841 2 43 0 cpu2 1664 0 1109 9447191 666 1 571 0 cpu3 864 0 716 9429250 387 2 118 0 cpu4 27667 110 5553 9358851 13900 2598 21784 0 cpu5 16625 146 2861 9388654 4556 4026 24979 0 cpu6 1790 0 1836 9436782 480 3307 19623 0 cpu7 1306 0 1702 9399053 726 3529 26756 0 intr 4421041070 559 10 0 4 5 0 0 0 26 0 0 0 111 0 129692 0 0 0 0 0 95 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 369 91027 1580921706 1277926101 570026630 991666971 0 277768 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 8097121 btime 1251365089 processes 63692 procs_running 2 procs_blocked 0 

Источник

Читайте также:  Linux terminal emulator on windows

Как просмотреть нагрузку на процессор в Linux

В Linux потребление ресурсов CPU, с сортировкой по наибольшей загрузке, можно посмотреть при помощи двух команд: ps и top.

Важный нюанс: Значение в столбце «CPU» в обоих командах считается от загрузки одного ядра процессора. Таким образом сумма процентов на многоядерных машинах будет больше 100%. К примеру для четырехядерного процессора суммарный процент потребления всех процессов не может превышать 400%.

Рассмотрим каждую из команд подробней.

Команда ps

Для запуска введите в консоли ОС команду:

$ 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 окт31 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 окт31 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 окт31 20:36 kwin_x11

Важными столбцами являются:

  • USER Пользователь, от имени которого работает процесс
  • PID Идентификатор процесса
  • %CPU Процент загрузки ядра

Согласно данному выводу можно понять, что экземпляр программы dd с PID=31712 практически полностью использует одно ядро процессора.

Команда top

Также загрузку процессора можно посмотреть в интерактивном режиме при помощи команды top. Для запуска введите в консоли ОС команду:

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

Важными столбцами являются:

  • USER Пользователь, от имени которого работает процесс
  • PID Идентификатор процесса
  • %CPU Процент загрузки ядра
Читайте также:  Events in linux kernel

Согласно данному выводу видно, что два процесса браузера Chromium используют по 40% возможностей одного из ядер процессора.

Источник

How/Where do I check my ubuntu laptops’s CPU usage?

Additionally, try out this page for more information. This is very comprehensive and surely answers a lot of queries, although I personally feel using system monitor is the best solution.

3 Answers 3

HTOP

is a lightweight text-mode process viewer packed with handy features such as killing processes without entering their PID, displaying full command lines, etc with a colour display

How to install

open your Terminal ( Ctrl — Alt — T ) and Type

To run: type htop This will show what you are asking. .

enter image description here

Why is this the accepted answer when an earlier answer provided a faster builtin solution? This answers questions that weren’t even asked.

@deanresin I completely agree with you. But if you know how to use htop then you will know how to monitor each CPU core performance. Thank you.

In your dash i.e. pressing super key search for system monitor application.

enter image description here

If you are comfortable with command line there are tools like top and htop where cpu usage can be viewed as well.

gnome-system-monitor is not installed by default on Ubuntu 18.04 anymore for some reason, you need sudo apt install gnome-system-monitor first: releases.ubuntu.com/18.04/ubuntu-18.04.3-desktop-amd64.manifest

As said in previous answer you can use system monitor which is the best tool. If you want more information you can try some commands on terminal

top — its a command to see all the processes and their CPU usage. Just read the screen carefully and you would find lot of other useful information there. you can press Ctrl + c to close it.

Читайте также:  Astra linux планировщик заданий

Or you can also try cat /proc/cpuinfo — for other information about cpu

Источник

Оцените статью
Adblock
detector