Detailed explanation of Linux TOP command

Detailed explanation of Linux TOP command

The meaning of the TOP command

The TOP command is a commonly used command for Linux performance monitoring. After execution, the interface is as follows:

first row

top-14:09:04 up 3 days, 21:20, 0 users, load average: 0.52, 0.58, 0.59

The current time (date), the system has been running time (last reboot), the number of currently logged in users (who), the average load in the last 5, 10, and 15 minutes

The meaning of CPU load

load average: 0.52, 0.58, 0.59It represents the 1min 5min 15minaverage load of the CPU

Generally, more than 1 means congestion, and it is normally controlled below 0.7. If it is multi-core, it needs to be divided by the number of cores.

What is the meaning of this load? What does 0.52 mean?

From the current time to the last minute in the past, an average of 0.59 processes (threads) are waiting for CPU processing. Simply put, there are (1-0.59)=0.41 CPUs that are idle.

If the current value is 2, it means that the current process (thread) with 2 times the CPU processing power is waiting for resources, and it does not mean that the CPU usage is very high.

In order to better understand the meaning of load, we assume that there are 4 tasks waiting for the CPU to process, and the time slice required for each task is 30s. As shown in the figure below:

If only Task1 is processed by the CPU within 1min, the CPU Load is 0.5 and the CPU usage rate is 60%

If Task1 and Task2 all need CPU processing within 1min, CPU Load is 1, and the CPU usage rate is 70%

If all 4 tasks need to be processed by the CPU within 1 min, the CPU Load is 55% of the usage rate of 2 CPUs.

Therefore, if you encounter the following four situations, you can easily locate the bottleneck of the server.

second line

Tasks: 10 total, 1 running, 9 sleeping, 0 stopped, 0 zombie

The total number of tasks, running tasks, sleeping tasks (processes waiting to be processed, it takes a time to wake up), stopped tasks (waiting for signals to be processed), zombies State (zombie) tasks

The third row

%Cpu(s): 5.7 us, 34.2 sy, 0.0 ni, 60.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

Field

Field Interpretation

us

user: The CPU time of running (without adjusting the priority) user process, generally below 60%

sy

system: CPU time sy+us <80% to run the kernel process

ni

niced: CPU time to run the user process with adjusted priority

id

idle: idle time

wa

IO wait: The CPU time used to wait for IO to complete is generally <30%

hi

CPU time to handle hardware interrupts

si

CPU time to process software interrupts

st

The CPU time stolen by the hypervisor for this virtual machine

Fourth row

MiB Mem: 32657.8 total, 13158.8 free, 19275.0 used, 224.0 buff/cache

All available memory, free memory, memory used by programs , buffer memory

The fifth line

MiB Swap: 15006.1 total, 12780.1 free, 2226.0 used. 13252.2 avail Mem

All, free, used, and buffer swap space

Monitoring information behind

Field

Paraphrase

PID

Process ID, the unique identifier of the process

USER

The actual user name of the process owner

PR

The scheduling priority of the process. Some values ​​of this field are'rt'. This means that these processes are running in real time.

NI

The nice value (priority) of the process. A smaller value means a higher priority. Negative value means high priority, positive value means low priority

VIRT

virtual memory usage Virtual memory, the virtual memory used by the process. The total amount of virtual memory used by the process, in kb. VIRT=SWAP+RES1. The virtual memory size "required" by the process, including the library, code, data, etc. used by the process. 2. If the process applies for 100m of memory, but only 10m is actually used, then it will grow by 100m instead of the actual Usage

RES

resident memory usage resident memory, resident memory size. Resident memory is the size of non-swap physical memory used by the task. The size of the physical memory used by the process that has not been swapped out, in kb. RES=CODE+DATA1. The memory size currently used by the process, but does not include swap out. 2, Contains the sharing of other processes. 3. If you apply for 100m of memory and the actual use is 10m, it only grows by 10m, which is the opposite of VIRT. 4. About the library occupancy In the case of memory, it only counts the memory size of the loaded library files

SHR

SHR: shared memory 1. In addition to the shared memory of its own process, it also includes the shared memory of other processes. 2. Although the process only uses a few shared library functions, it contains the size of the entire shared library. 3. Calculate a certain The formula for the size of the physical memory occupied by the process: RES-SHR 4. After swap out, it will drop

S

This is the status of the process. It has the following different values: D-Uninterruptible sleep state. R-running state S-sleeping state T-tracked or stopped Z-zombie state

%CPU

The percentage of CPU time used by the task since the last update. %CPU shows the percentage of a core that the process occupies, not the percentage of the entire cpu (N cores). Sometimes it may be greater than 100. That's because the process has enabled multi-threading and occupies multiple cores, so sometimes we look at this It will exceed 100% when it is worthwhile, but will not exceed the total number of cores*100

%MEM

Percentage of free physical memory used by the process

TIME+

The total CPU time used since the start of the task, accurate to one hundredth of a second

COMMAND

The command used to run the process. Process name (command name/command line)

Interactive command

Z: Modify font B: bold font

b: Add selected row

1: Show and hide CPUinformation

f: Enter the field display configuration mode, use the space bar to select and unselect.

s: Set refresh time

M: Sort according to the size of the resident memory.

P : Sort according to the percentage of CPU usage.

H: Show thread

c: Switch to display the command name and the complete command line.

Reference: https://cloud.tencent.com/developer/article/1780883 Linux TOP command detailed explanation-Cloud + Community-Tencent Cloud