Linux command - top related

Analysis of the top command of Linux operation and maintenance_linux top command_Zong Eryan's Blog-CSDN Blog

0 Background
When developing on the Linux system, the top command is often used to monitor processes and resources. This article introduces the output and usage of the command.

1 Output Analysis
The following figure shows the output after running the top command in my system

1.1 The first line
The first line is the task queue information, which is consistent with the output of the uptime command

14:18:36

system current time

up 151 days, 21:18,

System running time is 151 days 21 hours 18 minutes

13 users

Currently logged in users

load average: 0.37, 0.21, 0.22

CPU load, which is the average length of the task queue. The three values ​​are the average values ​​from 1 minute, 5 minutes, and 15 minutes ago to the present.

1.2 The second row
summary of process information

Tasks: 744 total

total number of processes

1 running

number of running processes

499 sleeping

number of sleeping processes

0 stopped

number of processes stopped

0 zombie

Number of Zombie Processes

1.3
CPU usage in the third row

%Cpu(s):  0.1 us,

CPU percentage occupied by user space
0.2 sy

CPU percentage occupied by kernel space
0.0 ni CPU percentage occupied by processes whose priority has been changed in user process space
99.7 id Idle CPU percentage
0.0 wa

Percentage of CPU time waiting for I/
O 0.0 hi

hardware IRQ, the percentage of CPU time occupied by hardware interrupts

0.0 and

software IRQ, the percentage of CPU occupied by soft interrupts
0.0 st Steal Time
1.4 The fourth and fifth lines
show the memory usage

KiB Mem : 65633064 total, total physical memory
21800724 free, total free memory
3450376 used, total physical memory used
40381964 buff/cache memory used as kernel cache
KiB Swap: 8000508 total, total swap area
7649788 free, The total amount of free swap area is
350720 used. The total amount of swap area used
is 61509196 The total amount of swap area buffered by avail Mem. The content in the memory is swapped out to the swap area, and then swapped into the memory, but the used swap area has not been overwritten. This value is the size of the swap area where these contents already exist in the memory. When the corresponding memory is swapped out again, there is no need to write to the swap area.
1.5 The sixth line,
the rest is the detailed information of the process

PID    
process ID number

USER User name of process owner
PR Process priority
NI nice value, negative value means high priority, positive value means
the total amount of virtual memory used by low priority VIRT process, unit kb. VIRT = SWAP + RES
The physical memory size used by the RES process and not swapped out, in kb. RES = CODE + DATA
SHR Shared memory size, unit kb
S Process state.
            D = Uninterruptible Sleep
            R = Running
            S = Sleeping
            T = Tracking/Stopping
            Z = Zombie Process
%CPU %CPU time since last update %
MEM %Physical memory used by process
TIME+ Total CPU time used by process, Unit 1/100 second
Command corresponding to COMMAND startup process
2 Command method
In the previous section, we introduced the content of the output of the conventional top command, and then introduced the commonly used command parameters

2.1 Shortcuts
After running top, you can press the corresponding letter below (case-sensitive) to switch some functions. I personally think that the useful ones are marked in red

h or ? : Display a help screen, giving some short summary instructions for the commands.
k : Terminate a process. The system will prompt the user to enter the PID of the process that needs to be terminated, and what kind of signal needs to be sent to the process. Generally, signal 15 can be used to terminate the process; if it cannot end normally, use signal 9 to force the process to end. The default is signal 15. This command is blocked in safe mode.
i: Ignore idle and zombie processes. This is a switch command.
q: Quit the program.
r: Rearrange the priority of a process. The system prompts the user to input the PID of the process to be changed and the priority value of the process to be set. Entering a positive value will make the priority lower, and a negative value will make the process have a higher priority. The default value is 10.
S: switch to accumulation mode.
s : Change the delay between refreshes. The system will prompt the user to enter a new time in s. If there is a decimal, convert it to ms. If you enter a value of 0, the system will refresh continuously, and the default value is 5 s. It should be noted that if the time is set too small, it may cause continuous refreshing, so that it is too late to see the display, and the system load will also increase greatly.
f or F : Add or remove items from the current display.
o or O : Change the order of displayed items.
l: Toggles the display of load average and startup time information. That is, the first line of hiding is displayed
. m: Switch to display memory information. That is, display hidden memory lines
t: Switch to display process and CPU status information. That is to display the hidden CPU line
c: switch to display the command name and the complete command line. Show the full command. This feature is very useful.
M : Sort according to the size of the resident memory.
P: Sort according to the percentage of CPU usage.
T: Sort according to time/cumulative time.
W: Write the current settings into the ~/.toprc file. This is the recommended way to write top configuration files.
2.2 Command line parameters 
We can also configure parameters with parameters at startup. First, only use the help command to check which parameters are supported

$ top -h
  procps-ng 3.3.12
Usage:
  top -hv | -bcHioss -d secs -n max -u|U user -p pid(s) -o field -w [cols]
-hv : output help information and Version information
-bcHioss: output some keywords
-d: adjust the output refresh interval, in seconds
-n: specify the number of updates
-u: monitor the process of the specified user
-p: monitor the process of the specified user
-o: specify which fields to sort by, Such as memory, CPU, etc.
-w: output width
So far, an analysis of the top command and an introduction to its application method have been completed. For a more detailed introduction, you can use the man command to view it.
————————————————
Copyright statement: This article is an original article of CSDN blogger "Zong Eryanzhi", following the CC 4.0 BY-SA copyright agreement, please attach the original source link for reprinting and this statement.
Original link: https://blog.csdn.net/zong596568821xp/article/details/125145832

Guess you like

Origin blog.csdn.net/liuqinhou/article/details/131269854