Detailed analysis of top command parameters in Linux

WBOY
Release: 2021-12-24 17:54:00
forward
3804 people have browsed it

This article brings you knowledge about the top command in Linux, including the usage of the top command and the meaning of each output parameter. I hope it will be helpful to you.

Detailed analysis of top command parameters in Linux

top command usage

The top command is often used to monitor the system status of Linux. It is a commonly used performance analysis tool that can display the status of each process in the system in real time. Resource usage.

How to use top top [-d number] | top [-bnp]

Parameter explanation:

-d: number represents the number of seconds, indicating the number displayed by the top command The interval between page updates. The default is 5 seconds. -b: Execute top in batch mode. -n: used in conjunction with -b, indicates that the output results of the top command need to be performed several times. -p: Specify a specific pid process number for observation.

On the page displayed by the top command, you can also enter the following keys to perform the corresponding functions (note that they are case-sensitive):

?: Display the commands that can be entered in top. P: Use the CPU's Sort by resource usage and display M: Sort by memory resource usage and display N: Sort by pid and display T: Sort by accumulated time used by the process and display k: Give a signal to a certain pid. Can be used to kill the process r: re-customize a nice value (i.e. priority) for a certain pid q: exit top (you can also exit top with ctrl c).

The meaning of each output parameter of top

The following is a screenshot of using the top command to perform performance testing:

Figure 1 (ubuntu):

Figure 2 (centos):

1. Statistical information of the first 5 rows of top

Row 1: top - 05:43:27 up 4:52, 2 users, load average: 0.58, 0.41, 0.30
The first line is the task queue information, its parameters are as follows:

##05:43:27represents the current timeup 4:52The system running time format is hours: minutes##2 usersload average: 0.58, 0.41, 0.30load average: If this number is divided by the number of logical CPUs, if the result is higher than 5, it indicates that the system is overloaded.
Content Meaning
Number of currently logged in users
System load, that 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 now.


Line 2: Tasks: 159 total, 1 running, 158 sleeping, 0 stopped, 0 zombie
Line 3: %Cpu(s): 37.0 us , 3.7 sy, 0.0 ni, 59.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
The 2nd and 3rd lines are process and CPU information When there are multiple CPUs, these contents may There will be more than two lines, and the parameters are as follows:

##ContentMeaning 159 totalTotal number of processes1 runningNumber of running processes158 sleepingNumber of sleeping processes0 stoppedNumber of stopped processes0 zombieNumber of zombie processes37.0 usCPU percentage occupied by user space3.7 syCPU percentage occupied by kernel space0.0 ni59.3 idIdle CPU percentage0.0 waPercentage of CPU time waiting for input and output0.0 hi0.0 si##0.0 stLine 4: KiB Mem: 1530752 total, 1481968 used, 48784 free, 70988 buffers
CPU percentage occupied by processes that have changed priorities in the user process space
Percentage of CPU occupied by Hardware IRQ
Percentage of CPU occupied by software interrupts
Line 5: KiB Swap: 3905532 total, 267544 used, 3637988 free . 617312 cached Mem

The 4th and 5th lines are memory information
The parameters are as follows:



##Content

MeaningKiB Mem: 1530752 totalTotal physical memory1481968 usedPhysical used Total memory48784 freeTotal free memory70988 buffers(buff/cache)Amount of memory used for kernel cacheKiB Swap: 3905532 totalTotal amount of swap area267544 used Total amount of swap area used3637988 freeTotal amount of free swap area617312 cached MemThe total amount of cached swap area. 3156100 avail MemRepresents the amount of physical memory available for the next allocation of the process

The total amount of the buffered swap area mentioned last is explained here. The so-called total buffered swap area means that the content in the memory is swapped out to the swap area, and then swapped into the memory, but the used The swap area has not been overwritten, and this value is the size of the swap area where these contents already exist in memory. When the corresponding memory is swapped out again, there is no need to write to the swap area.

There is an approximate formula for calculating the amount of available memory:
free on the fourth line buffers on the fourth line cached on the fifth line

2. Process information

Column name Meaning
PID Process id
PPID Parent process id
RUSER Real user name
UID User ID of the process owner
USER Username of the process owner
GROUP Group name of the process owner
TTY Terminal name for starting the process. Processes that are not started from the terminal are displayed as?
PR Priority
NI nice value. Negative values ​​indicate high priority, positive values ​​indicate low priority
P The last CPU used is only meaningful in a multi-CPU environment
%CPU CPU time usage percentage since last update
TIME Total CPU time used by the process , unit second
TIME Total CPU time used by the process, unit 1/100 second
%MEM Percentage of physical memory used by the process
VIRT The total amount of virtual memory used by the process, in kb. VIRT=SWAP RES
SWAP The size of the virtual memory used by the process that is swapped out, unit kb
RES The size of the physical memory used by the process and not swapped out, in kb. RES=CODE DATA
CODE The physical memory size occupied by the executable code, unit kb
DATA The physical memory size occupied by parts other than the executable code (data segment stack), unit kb
SHR Shared memory size, unit kb
nFLT Number of page errors
nDRT The page that has been modified since the last time it was written number.
S Process status. D=uninterruptible sleep state R=run S=sleep T=track/stop Z=zombie process
COMMAND Command name/command line
WCHAN If the process is sleeping, the name of the system function in sleep is displayed
Flags Task flag

Others

When entering top by default, the processes are sorted according to CPU usage.

1. In the top basic view, press the keyboard number "1" to monitor the status of each logical CPU:


2. Press the keyboard 'b' ( Turn on and off the highlighting effect) The top view changes as follows:

PID 16283 is the only running process in the current top view. You can also press 'y' on the keyboard to turn on or off the highlighting effect of running processes.

3. Press 'x' on the keyboard (turn on/off the highlighting effect of the sort column), the top view changes as follows:

You can see now It is sorted by "%CPU". You can press "shift >" or "shift <" to change the sorting sequence.

4. Change the process display field

In the top basic view, tap "f" to enter another view, where you can edit the display fields in the basic view:

Use the up and down keys to select an option, and press the space bar to decide whether to display this option in the basic view.

The top command is a very powerful function, but the smallest unit it monitors is a process. If you want to monitor a smaller unit, you need to use the ps or netstate command to meet our requirements.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of Detailed analysis of top command parameters in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template