The Top command is a common performance analysis tool under Linux that shows the resource usage of each process in the system in real time.
top –00:01:51 up 2:43, 1 user, Load average:0.00, 0.00, 0.00
tasks:69 Total, 1 running, sleeping, 0 stopped, 0 zombie
Cpu (s): 0.2%us, 0.7%sy, 0.1%ni, 97.8%id, 1.1%wa, 0.1%hi, 0.1%si, 0%
mem:255420k Total, 234352k used, 21068k free, 15104k buffers
swap:524280k Total, 96k used, 524184k free, 149024k cached
PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
1 root 0 2072 592 S 0.0 0.2 0:01.07 Init
2 root RT-5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 Root 0 0 0 S 0.0 0.0 0:00.07 ksoftirqd/0
4 root RT-5 0 0 0 S 0.0 0.0 0:00.01 watchdog/0
5 root 10-5 0 0 0 S 0.0 0.0 0:00.03 events/0
6 root 10-5 0 0 0 S 0.0 0.0 0:00.13 khelper
Statistical information Area:
The first five elements are the statistical information of the whole system. The first line is the task queue information, with the execution result of the uptime command.
00:01:51 Current Time
Up 2:43 system run time, format last: minutes
1 user Current number of users logged on
Load average:0.00, 0.00, 0.00 System Load, which is the average length of the task queue.
The three values were 1 minutes, 5 minutes, and 15 minutes ago to the present average.
The second to third behavior process and CPU information. When there are multiple CPUs, the content may be more than two lines.
tasks:69 Total Process Totals
1 running number of running processes
Sleeping the number of sleep processes
0 Number of processes stopped stopped
0 Zombie Number of zombie processes
CPU (s): 0.2% US user space consumes CPU percentage
0.7% SY core space CPU percent occupied
0.1% CPU Percentage of processes that have changed priority within NI user process space
97.8% ID Idle CPU percent
1.1% wa wait for the input output CPU time percentage
0.1% hi
0.1% si
The last two behavior memory information.
mem:255420k Total Physical Memory
Total physical memory used by 234352k used
21068k free Memory Total
The amount of memory that 15104k buffers uses as the kernel cache
Total swap area of swap:524280k
Total swap area used by 96k used
524184k Free Swap Area total
149024k cached Buffers The total number of swap areas.
The in-memory content is swapped out to the swap area and then swapped in to memory, but the used swap area has not been overwritten.
This value is the size of the swap area where the content already exists in memory.
When the corresponding memory is swapped out again, it is no longer necessary to write to the swap area.
Process Information Area:
The details of each process are shown below the statistics area. Let's start by understanding the meaning of the columns.
Ordinal column name meaning
A PID process ID
bPPID Parent Process ID
C ruser Real User name
D UID Process Owner's user ID
e username of user process Owner
Group name of the F group Process owner
The terminal name of the G TTY boot process. Processes that are not started from the terminal are displayed as?
H PR-Priority
I NI nice value. Negative values indicate high priority, positive values indicate low priority
The last CPU used by J P is meaningful only in a multi-CPU environment
K%cpu CPU time consumption percentage last updated to current
The total CPU time, in seconds, used by the timing process
The total CPU time used by the M time+ process, in units 1/100 seconds
NPercentage of physical memory used by the%MEM process
o The total amount of virtual memory used by the VIRT process, in kilobytes. Virt=swap+res
The P swap process uses the size of the virtual memory, which is swapped out, in kilobytes.
The size of the physical memory, in kilobytes, that the Q RES process uses and has not been swapped out. Res=code+data
R code executable code occupies the physical memory size, in kilobytes
The amount of physical memory that is used outside of the S data executable code (data segment + stack), in kilobytes
T SHR shared memory size, in kilobytes
U Nflt page Error count
V NDRT the number of pages that have been modified in the last write to now.
W S Process state.
d= non-disruptive sleep state
R= Run
S= Sleep
t= Tracking/Stopping
z= Zombie Process
x command name/command line
Y Wchan If the process is sleeping, the system function name in sleep is displayed
Z Flags task Flag, reference sched.h
By default, only the more important PID, USER, PR, NI, VIRT, RES, SHR, S,%cpu,%MEM, time+, and COMMAND columns are displayed. You can change the display by using the following shortcut keys.
To change what is displayed:
The F key allows you to select what is displayed. Press the F key to display a list of columns, press A-Z to show or hide the corresponding column, and then press ENTER to confirm.
Press the O key to change the order in which the columns are displayed. A-Z in the lower case moves the corresponding column to the right, while the uppercase A-Z moves the corresponding column to the left. Finally, press ENTER to confirm.
Press the uppercase F or O key, and then press A-Z to sort the process by the appropriate column. The uppercase R key can reverse the current sort.
Command usage explained:
1. Brief introduction
Display the current process and other status of the system;
Top is a dynamic display process in which the current state can be refreshed continuously by a user key. If the command is executed in the foreground, it will monopolize the foreground until the user terminates the program. More accurately, thetop command provides real-time status monitoring of the system's processor. It will display the most "sensitive" task list on the system. This command can be used by CPU. Memory usage and execution time sorting tasks , and many of the features of the command can be set through interactive commands or in personal customization files.
2. Usage
2. 1 Using formats
Top [-] [d] [U] [P] [N] [b] [Q]
S [S] I
2. 2 parameter description
d Specifies the interval between every two times the screen information is refreshed. Of course the user can use the s interactive command to change it.
U view only the process of the specified user name
P only monitors the status of a process by specifying the monitoring process ID
N Set the number of screen refreshes before exiting
b organize the top output into a format suitable for output to a file, you can use this option to create a process log
Q This option will cause top to refresh without any delay. If the calling program has Superuser privileges, top will run at the highest priority level
C Displays the entire command line instead of just displaying the command name
S Specifies the cumulative mode
s enables the top command to run in Safe mode. This removes the potential danger of interactive commands.
I make top not show any idle or zombie processes.
2.3 Interactive Command Description
Below is a description ofTopSome of the interactive commands that can be used during the execution of a command. From a point of view of use, mastering these commands is more important than mastering the options. These commands are single-letter, and if you use the S option in command-line options, some of these commands may be masked out.
shift+NSort by PID
Shift+p Sort by CPU
Shift+m Sort by memory usage
Shift+t Sort by CPU time
Shift+</shift+> sort by the next left column/Sort by the next column on the right
U Enter user name to display only the process of the specified user
NType a number to see a specified number of processes, press = at any time to reply to the originalTopShow
H or? Display the help screen and give some brief summary of the commands
K Terminates a process. The user will be prompted for the process PID to be terminated and what signal needs to be sent to the process. The normal termination process can use a 15 signal, and if not, use signal 9 to force end the process. The default value is signal 15. This command is masked in safe mode
I ignore idle and zombie processes. This is a switch-type command.
Q quit the program.
R reschedule the priority level of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value that needs to be set. Entering a positive value lowers the priority and, conversely, it gives the process a higher priority. The default value is 10.
S switch to cumulative mode.
s changes the delay time between two refreshes. The user will be prompted to enter a new time in S. If there are decimals, it is converted into Ms. Enter a value of 0 and the system will continue to refresh, the default value is 5s. It is important to note that if you set too small a time, it is likely to cause a constant refresh, so it is too late to see the display, and the system load will be greatly increased.
D function Ibid.
F or F Add or remove items from the current display.
O or O change the order in which items are displayed.
L Toggle Display Average load and start time information.
M toggles display memory information.
T toggles the display of process and CPU status information.
The C toggle Displays the command name and the full command line.
M sorts based on the size of the resident memory.
P is sorted according to the percentage size of CPU usage.
T is sorted by time/accumulated time.
W writes the current settings to the ~/.TOPRC file. It's writtenTopRecommended method for configuring files.
2.3 Example
[[email protected] ~]# top -D 5 Update delay set to 5 seconds (default 3 seconds)
[[email protected] ~]# top -u MySQL only view the process of a valid user named MySQL
[[email protected] ~]# top -p 200,2000 only view processes 200 and 2000
[[email protected] ~]# top -n 8 before exiting the screen and then refreshing 10 times
[[email protected] ~]# top -b runs in non-interactive and non-full-screen mode
[[email protected] ~]# top -b -n 12000 > Plog run top and record command output for 10 hours, Save to Plog file
The Linux top command is detailed