top command in Linux

The top command is the most intuitive and easy to use command to view server load. It dynamically refreshes and displays server status information in real time, and can customize the display content through interactive commands, which is very powerful.

Type in the terminal, topand the following will be displayed after pressing Enter:

top - 21:48:39 up  8:57,  2 users,  load average: 0.36, 0.24, 0.14 Tasks: 322 total, 2 running, 320 sleeping, 0 stopped, 0 zombie %Cpu(s): 5.0 us, 1.7 sy, 0.0 ni, 93.0 id, 0.0 wa, 0.3 hi, 0.0 si, 0.0 st KiB Mem: 1010504 total, 937416 used, 73088 free, 23708 buffers KiB Swap: 1046524 total, 280708 used, 765816 free. 365556 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 8096 root 20 0 320624 38508 21192 S 1.7 3.8 0:41.03 Xorg 13536 tabalt 20 0 697336 104272 56776 S 1.7 10.3 0:08.29 gnome-langu+ 9426 tabalt 20 0 1213228 72976 16860 S 1.0 7.2 2:07.27 compiz 197 root 20 0 0 0 0 S 0.3 0.0 0:36.13 kworker/0:2 1009 root 20 0 303112 3392 1500 S 0.3 0.3 0:00.93 polkitd 9670 tabalt 20 0 325932 4300 2256 S 0.3 0.4 0:40.27 vmtoolsd 14016 root 25 5 43940 2408 2000 S 0.3 0.2 0:01.12 http 14149 tabalt 20 0 591180 19504 12820 S 0.3 1.9 0:00.45 gnome-termi+ 1 root 20 0 33648 1972 744 S 0.0 0.2 0:01.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 0:02.80 ksoftirqd/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root 20 0 0 0 0 S 0.0 0.0 0:05.55 rcu_sched 8 root 20 0 0 0 0 R 0.0 0.0 0:03.43 rcuos/0 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuos/1 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuos/2 

1. System Information Statistics

The first five lines are the statistical information display area of ​​the overall status of the system. The following describes the content of each line separately:

1. The first line shows the server overview

As shown below, the first line lists how long the server has been running, how many users are currently logged in, the load on the server, etc. The uptimesame result can be obtained using the command.

top - 21:48:39 up  8:57,  2 users,  load average: 0.36, 0.24, 0.14 / / / \ 当前时间 运行时长 当前登录用户数 平均负载(1分钟、5分钟、15分钟) 

The smaller the value of the average load, the smaller the system pressure is, and the larger the value is, the higher the system pressure is. Usually, we will use the last value, which is the average load in 15 minutes, as a reference to evaluate the load of the system.

For a system with only a single-core CPU, it 1.0is the boundary value of the load that the system can bear. If it is greater than 1.0, processing needs to wait.

For a single-core cpu system, the appropriate value for the average load is the 0.7following. If the load is hovering at 1.0 for a long time, it needs to be considered immediately. Loads exceeding 1.0 may have very serious consequences.

Of course, for a multi-core CPU system, the number of CPU cores is multiplied by the aforementioned value. For example, for a multi-core CPU system, if there are N cores, the limit value that can be tolerated is N.0.

You can use the following command to view information about each processor:

cat /proc/cpuinfo

If you just want to count how many cpu cores there are, you can use the following command:

cat /proc/cpuinfo | grep 'model name' | wc -l

2. The second line is the process information:

Tasks: 322 total,   2 running, 320 sleeping,   0 stopped,   0 zombie
        /                /            /             /            /
    进程总数      正运行进程数    睡眠进程数   停止进程数    僵尸进程数

3. The third line is the CPU information:

%Cpu(s):  
5.0 us      用户空间CPU占比
1.7 sy      内核空间CPU占比
0.0 ni      用户进程空间改过优先级的进程CPU占比
93.0 id 空闲CPU占比 0.0 wa 待输入输出CPU占比 0.3 hi 硬中断(Hardware IRQ)CPU占比 0.0 si 软中断(Software Interrupts)CPU占比 0.0 st - 

4. The fourth line is the memory information:

KiB Mem:   1010504 total,   937416 used,    73088 free,    23708 buffers / / / / 物理内存总量 使用中总量 空闲总量 缓存的内存量 

5. The fifth line is the swap partition information:

KiB Swap:  1046524 total,   280708 used,   765816 free,   365556 cached Mem / / / / 交换区总量 使用中总量 空闲总量 缓存的内存量 

2. Process (task) status monitoring

The seventh row and below shows the status monitoring of each process (task). The meanings of the columns are as follows:

PID         进程id
USER        进程所有者
PR          进程优先级
NI          nice值。负值表示高优先级,正值表示低优先级
VIRT        进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES         进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR         共享内存大小,单位kb
S           进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU        上次更新到现在的CPU时间占用百分比
%MEM        进程使用的物理内存百分比
TIME+       进程使用的CPU时间总计,单位1/100秒
COMMAND     进程名称(命令名/命令行)

3. Interact with top

  • Press key bto turn on or off highlighting of running processes

  • Press the key xto toggle the highlighting of sort columns on or off

  • shift + > or  you can change the sort column to the right or left shift + <

  • fkey to enter the view of editing the fields to be displayed, fields marked with * will be displayed, and fields without * will not be displayed, you can select or cancel fields according to the prompts on the page.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325321494&siteId=291194637