Linux cpu load process

Как просмотреть нагрузку на процессор в 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 Процент загрузки ядра
Читайте также:  Linux x64 11gr2 database 1of2 zip

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

Источник

How to Check CPU Utilization in Linux with Command Line

Understanding CPU processor usage is important for overall system-performance measurement. From Linux enthusiasts to system admins, knowing how to monitor CPU utilization in Linux from the command line is crucial.

This guide will walk you through several options to check Linux CPU usage.

Article on how to check CPU utilization in Linux from the terminal.

  • A Linux-based computer (e.g., Ubuntu and CentOS)
  • Access to a user account with sudo privileges
  • A command prompt (Ctrl-Alt-T in Ubuntu, Menu > Applications > Utilities > Terminal in CentOS)
  • (optional) A package installer, like apt or yum, usually included by default

Note: Use one of 5 available commands in Linux to check memory usage.

How To Check CPU Usage from Linux Command Line

top Command to View Linux CPU Load

Open a terminal window and enter the following:

The system should respond by displaying a list of all the processes that are currently running. It will also give a readout of users, tasks, CPU load, and memory usage.

This list can frequently change, as background tasks start and complete. One helpful switch is to launch top with the –i switch:

This hides all the idle processes, making it easier to sort through the list.

To quit the top function, press the letter q on your keyboard.

Some other useful commands while top is running include:

  • M – sort task list by memory usage
  • P – sort task list by processor usage
  • N – sort task list by process ID
  • T – sort task list by run time
Читайте также:  Linux postgres командная строка

To get assistance with top , you can press the letter h while it’s running. Or, you can enter the following at a command line:

This will display the manual page for the top command.

mpstat Command to Display CPU Activity

Mpstat is part of a software bundle called sysstat. Most RHEL-based distributions include this software package.

For Debian and Ubuntu systems, you’ll need to install the sysstat package.

In a terminal window, enter the following:

sudo apt-get install sysstat

Allow the process to complete.

If you’re running an older (4.x or older) version of CentOS or Red Hat derivative, you can use up2date to install sysstat:

sudo up2date install sysstat

For newer (5.x and later) installations of CentOS or Red Hat, sysstat can be installed using the following command:

Once the process finishes, you can use the mpstat command in the terminal as follows:

The system will display usage for each processor (or processor core).

The first line is a set of column labels. The second line is the value for each column:

  • %usr – % CPU usage at the user level
  • %nice – % CPU usage for user processes labeled “nice”
  • %sys – % CPU usage at the system (Linux kernel) level
  • %iowait – % CPU usage idling waiting on a disk read/write
  • %irq – % CPU usage handling hardware interrupts
  • %soft – % CPU usage handing software interrupts
  • %steal – % CPU usage being forced to wait for a hypervisor handling other virtual processors
  • %guest – % CPU usage spent running a virtual processor
  • %idle – % CPU usage on idle time (no processes, and not waiting on a disk read/write)
Читайте также:  Linux how to install run file

You can add switches to the mpstat command.

The –P switch allows you to specify a single processor to report:

This would show you a report for the first processor (CPU 0).

This command would show you the total, like the basic mpstat command. It will also list processes by individual CPU.

The mpstat command only takes a snapshot of CPU usage.

To take a series of snapshots, use a number to indicate an interval and a second number to indicate the number of reports:

This example would generate 7 snapshots, each 5 seconds apart.

sar Command to Show CPU Utilization

The sar tool is a utility for managing system resources. It’s not limited strictly to CPU usage, but you can use the -u option to track CPU performance.

Use the following command to direct sar to monitor CPU usage at set intervals:

The –u option tells it to display CPU usage. The 5 indicates that it should display every 5 seconds. This will run indefinitely. To cancel, press Ctrl-C.

iostat Command for Average Usage

In a terminal, enter the following:

The system will display average CPU usage since the last boot. It will also display input/output load (disk read/write activity).

More information on iostat can be found on the Linux Manual pages.

Other Options to Monitor CPU Performance

Nmon Monitoring Tool

Nmon is a monitoring tool developed by Nigel Griffiths of IBM. To install Nmon on Ubuntu, enter the following:

To install to CentOS, enter the following:

The command to launch nmon is:

This will launch the utility, and display all the options. To view CPU usage, press the letter c. To switch back, press c again. For a list of commands, press h. To quit, press q.

Graphical Utility Option

Many server systems don’t waste processor cycles on a graphical user interface (GUI).

However, you may have a lightweight GUI, or you may be using a client Linux system. Some versions, like Ubuntu, have a built-in graphical monitoring tool.

To launch Ubuntu’s system monitor, enter the following in a terminal window:

This starts a task-manager-like application where you can monitor tasks and CPU usage.

Typically, GUI’s have a “task manager” or “system monitor” application. This can be used to monitor CPU usage in real-time.

There are many different methods to check CPU usage in Linux.

This guide outlines the primary methods using built-in Linux tools or third-party applications. These commands will help you track processor usage and performance of your system, giving you greater control.

Источник

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