1. Main functions of the top command
In Linux, you can run the top command to dynamically view information about the CPU, memory, running time, swap partition, and execution threads. You can use the top command to effectively find system defects. The memory is not enough, the CPU processing capacity is not enough, or the I/O reading and writing is too high… .
[root@ubuntu]# top top-21:31:26 up 15:16, 5 Users, Load Average: 0.61, 0.82, 0.75 Tasks: 240 total, 2 running, 238 sleeping, 0 stopped, 0 zombie %Cpu(s): 13.7us, 1.5sy, 0.0Ni, 84.2ID, 0.6wa, 0.0hi, 0.0Si, 0.0st KiB Mem: 3775264 total, 250100 free, 2495300 used, 1029864 buff/cache KiB Swap: 4064252 total, 2789544 free, 1274708 used. 527664 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 16507 kiosk 20 0 1935284 201988 10816 R 46.8 5.4 68:11.92 plugin-con+ 15773 kiosk 20 0 1784208 497692 40776 S 4.7 13.2 37:05.32 Firefox 408 root 20 0 36940 4116 3920 S 3.0 0.1 4:51.67 SYSTEMd-JO + 3789 kiosk 20 0 747664 14124 4696 S 2.0 0.4 2:49.76 gnOMe-term + 2404 root 20 0 439488 106688 84580 S 1.7 2.8 16:08.35 Xorg 2662 kiosk 9-11 700096 5232 3032 S 1.7 0.1 5:17.25 pulseaudio 21632 Kiosk 20 0 812940 167440 30100 S 1.7 4.4 20:15.48 WPS 2688 kiosk 20 0 2111764 218776 18580 S 1.3 5.8 20:25.33 Gnome-shell 663 root 20 0 399976 3352 2984 S 1.0 0.1 0:46.92 rsyslogd 7349 qEMu 20 0 1697464 956932 556s 0.7 25.3 gnOMe-shell 663 root 20 0 399976 3352 2984 S 1.0 0.1 0:46.92 rsyslogd 7349 qEMu 20 0 1697464 956932 556s 0.7 25.3 5:03.80 QEMu-KVM 7803 QEMU 20 0 1697460 708164 544 S 0.7 18.8 4:16.74 QEMu-KVM 18 root 20 0 0 0 S 0.3 0.0 0:16.94 Rcuos /1 21 root 20 0 0 0 S 0.3 0.0 0:19.62 rcuos/3 671 root 20 0 207984 160 120 S 0.3 0.0 0:01.60 abrt-watch+ 5676 root 20 00 00 S 0.3 0.0 00.28 kworker/u1+ 1 root 20 0 189128 2900 1432 S 0.0 0.1 0:06. 11 systemdCopy the code
2. Read the parameters of the top command
2.1 the first line
Top-21:31:26 UP 15:16, 5 Users, Load Average: 0.61, 0.82, 0.75Copy the code
This line of information is the same as that displayed with the uptime command. What do these parameters mean? One to one correspondence in order:
Current system time Up Indicates the running time of I, the number of users logged in to the system, and the following three numbers of load Average indicate the load status one minute, five minutes, and fifteen minutes from now.
Note: The Load Average data is the number of active processes checked every 5 seconds and calculated according to a specific algorithm. If this number is divided by the number of logical cpus, anything above 5 indicates that the system is overloaded.
2.2 the second line
Tasks: 240 total, 2 running, 238 sleeping, 0 stopped, 0 zombie
Copy the code
One to one correspondence in order:
Tasks indicates tasks (processes), 240 total indicates 240 processes, of which 2 are running and 238 are dormant (suspended). Stopped indicates 0 processes, and zombie indicates 0 processes.
2.3 the third line
%Cpu(s): 13.7us, 1.5sy, 0.0Ni, 84.2ID, 0.6wa, 0.0hi, 0.0Si, 0.0stCopy the code
One to one correspondence in order:
Us: percentage of CPU usage by user space SY: percentage of CPU usage by system kernel space NI: Niced Percentage of CPU usage by processes whose priorities have changed WA :IO Wait percentage of CPU usage by IO wait Hi :Hardware IRQ CPU usage of hard interrupts SI :software CPU usage of soft interrupts ST: time stolen by the hypervisor
2.4 the fourth row
KiB Mem : 3775264 total, 250100 free, 2495300 used, 1029864 buff/cache
Copy the code
One to one correspondence in order:
Total physical memory (3.7GB), total free memory (2.5g), total memory in use (2.4g), and amount of buffer memory
In line 4, used refers to the amount of memory currently controlled by the kernel, and free refers to the amount that the kernel does not yet control. Not all kernel managed memory is in use, including memory that was used in the past and can now be reused. The kernel does not return this reusable memory to free, so on Linux there will be less and less free memory, but don’t worry about that.
2.5 the fifth row
KiB Swap: 4064252 total, 2789544 free, 1274708 used. 527664 avail Mem
Copy the code
One to one correspondence in order:
Total number of swap areas (4G), total number of idle swap areas (2.7GB), total number of used swap areas (1.2g), and total number of available swap areas
For memory monitoring, in top we should always monitor the fifth line of swap partition used. If this value is constantly changing, it indicates that the kernel is constantly exchanging data between memory and swap, which is the real memory is insufficient.
2.6 The sixth line is empty, followed by the seventh
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
Copy the code
One to one correspondence in order:
PID – Process ID USER – Process owner PR – Process priority NI – Nice value. A negative value indicates a high priority. A positive value indicates a low priority. VIRT – Total virtual memory used by a process, in KB. VIRT=SWAP+RES RES – Size of the physical memory used by the process that has not been swapped out, in KB. RES=CODE+DATA SHR – Shared memory size (unit: KB) S – Process status. D= Uninterruptable sleep R= Running S= sleep T= Trace/Stop Z= zombie process %CPU – CPU TIME occupied since last update %MEM – Percentage of physical memory used by process TIME+ – Total CPU TIME used by process, Unit 1/100 second COMMAND – Process name (COMMAND name/COMMAND line)