@[toc]

TOP is a dynamic display process, that is, the current state can be continuously refreshed by the user’s keystrokes. If this command is executed in the foreground, it monopolizes the foreground until the user terminates the program. More specifically, the top command provides real-time monitoring of the state of the system processor.

The following is a screenshot of a performance check using the top command:

Meanings of Parameters

I. Top 5 rows of statistics

Line 1: top-05:43:27 UP 4:52, 2 users, load Average: 0.58, 0.41, 0.30 line 1: task queue information, its parameters are as follows:

content meaning
05:43:27 Represents the current time
up 4:52 System running time format: minute
2 users Current Number of logged Users
Load Average: 0.58, 0.41, 0.30 The system load is the average length of the task queue. The three values are the average values of 1 minute, 5 minutes, and 15 minutes ago.

Load Average: If this number is divided by the number of logical cpus, anything above 5 indicates that the system is overloaded.

Line 2: Tasks: 159 total, 1 running, 158 sleeping, 0 stopped, 0 zombie 37.0us, 3.7SY, 0.0Ni, 59.3ID, 0.0wa, 0.0hi, 0.0Si, 0.0st This information may exceed two lines if there are more than one CPU:

content meaning
159 total The total number of processes
1 running Number of running processes
158 sleeping Number of sleep processes
0 stopped Number of stopped processes
0 zombie Zombie process Count
37.0 us CPU usage percentage of user space
3.7 sy Percentage of CPU occupied by kernel space
0.0 ni CPU usage percentage of user process space that has changed priority
59.3 id Percentage of idle CPU
0.0 wa Percentage of CPU time spent waiting for input and output
0.0 the hi Hardware IRQ Indicates the percentage of cpus consumed by hard interrupts
0.0 Si, 0.0 ST The total amount of Time the CPU spent serving soft interrupts, Steal Time


第4行 : KiB Mem: 1530752 Total, 1481968 used, 48784 free, 70988 Buffers 第5行 : KiB Swap: 3905532 Total, 267544 Used, 3637988 Free. 617312 Cached Mem Memory parameters for behavior 4 and 5 are as follows:

content meaning
KiB Mem: 1530752 total Total physical memory
1481968 used Total amount of physical memory used
48784 free Total free memory
70988 buffers The amount of memory used for the kernel cache
KiB Swap: 3905532 total Total exchange area
267544 used Total amount of swap area used
3637988 free Total free swap area
617312 cached Mem The total number of buffer swap areas.

The total amount of cached swap, which is the amount of memory that has been swapped out and then swapped back into memory but has not been overwritten, is the amount of memory that has been swapped out and then swapped back into memory. The corresponding memory can be swapped out again without writing to the swap area. There is an approximate formula for calculating the amount of available memory: Free on line 4 + buffers on line 4 + cached on line 5

Second, process information

The column name meaning
PID The process id
PPID The parent process id
RUSER Real user name
UID User ID of the process owner
USER User name of the process owner
GROUP Group name of the process owner
TTY Name of the terminal that starts the process. Processes that are not started from the terminal are displayed as?
PR priority
NI The nice value. A negative value indicates a high priority and a positive value indicates a low priority
P The last CPU used is only meaningful in a multi-CPU environment
%CPU Percentage of CPU time occupied since last update
TIME Total CPU time used by a process, in seconds
TIME+ Total CPU time used by a process, in 1/100 of a second
%MEM Percentage of physical memory used by a process
VIRT Total amount of virtual memory used by a process (unit: KB) VIRT=SWAP+RES
SWAP The size of virtual memory used by a process to be swapped out, in KB
RES The amount of physical memory used by a process that has not been swapped out, in KB. RES=CODE+DATA
CODE The size of physical memory occupied by executable code, in kilobytes
DATA The amount of physical memory, in kilobytes, that is not used by executable code (data segment + stack)
SHR The size of the shared memory, expressed in KB
nFLT Page error times
nDRT Number of pages modified since last written.
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 Mission marks

You can change the display by using the following shortcut keys: Change display Contents Use f key to select the display contents (press F key to display the column list, press A-Z to display or hide the corresponding column, and press Enter to confirm) Press O key to change the display order of columns (press lowercase A-Z to move the corresponding column to the right, Uppercase A-Z moves the corresponding column to the left and press Enter to confirm.) Pressing uppercase F or O and then A-z sorts the process by the corresponding column, while uppercase R reverses the current sorting.


Three, the use of skills

1. By default, the top command displays the previous part of the process. To view the information about all processes, run the top-ab -n 1 command.

2. After using top-ab-n 1 to output all process information, you can use AWK and other similar tools statistics, such as: statistics of all processes using HTTPD COMMAND memory.

3. You can also use the command top – an – n 1 | grep HTTPD, check all the HTTPD process information, the following figure:

The top / / every5Displays the resource usage of all processes in seconds top-d2/ / every2Displays the resource usage of all processes in seconds top-c // every other5Displays the resource usage of a process in seconds, and displays the command line parameters of the process (by default, only the process name) top -p12345 -p 6789/ / every5Seconds indicates pid yes12345And pid is6789Resource usage of the two processes of top-d2 -c -p 123456/ / every2Seconds indicates pid yes12345The resource usage of the process, and an explicit command line argument to start the processCopy the code