The top command is a common performance analysis tool in Linux. it can display the resource usage of various processes in the system in real time. it is similar to how to use it in the Windows Task Manager. Top is a dynamic display process. you can press the buttons to refresh the current status. if you execute this command on the foreground, it excludes the foreground until the user terminates the program. more accurately, the top command provides real-time monitoring of the status of the system processor. it displays the list of CPU-sensitive tasks in the system. this command can be used by CPU. the memory usage and execution time are used to sort tasks. many features of this command can be set through interactive commands or in a custom file.
1. command format:
Top [Parameters]
2. command functions:
Displays information about the processes being executed by the system, including the process ID, memory usage, and CPU usage.
3. command parameters:
-Batch B processing
-C: Display the complete governance command
-I ignore the failure process
-S Security mode
-S cumulative mode
-I <时间> Set the interval
-U <用户名> User name
-P <进程号> Process
-N <次数> Number of cycles
4. example:
Instance 1: displays process information
Command: top
Output:
Copy codeThe code is as follows:
[Root @ TG1704 log] # top
Top-14:06:23 up 70 days, 2 users, load average: 1.25, 1.32, 1.35
Task: 206 total, 1 running, 205 sleeping, 0 stopped, 0 zombie
Cpu (s): 5.9% us, 3.4% sy, 0.0% ni, 90.4% id, 0.0% wa, 0.0% hi, 0.2% si, 0.0% st
Mem: 32949016 k total, 14411180 k used, 18537836 k free, 169884 k buffers
Swap: 32764556 k total, 0 k used, 32764556 k free, 3612636 k cached
Pid user pr ni virt res shr s % CPU % mem time + COMMAND
28894 root 22 0 1501 m 405 m 10 m S 52.2 1.3: 16 java
18249 root 18 0 3201 m 1.9g 11 m S 35.9 6.0 569: 39.41 java
2808 root 25 0 3333 m 1.0g 11 m S 24.3 3.1 526: 51.85 java
25668 root 23 0 3180 m 704 m 11 m S 14.0 2.2 360: 44.53 java
574 root 25 0 3168 m 611 m 10 m S 12.6 1.9: 556 java
1599 root 20 0 3237 m 1.9g 11 m S 12.3 6.2 262: 01.14 java
1008 root 21 0 3147 m 842 m 10 m S 0.3 2.6. 08 java
13823 root 23 0 3031 m 2.1g 10 m S 0.3 6.8 176: 57.34 java
28218 root 15 0 12760 1168 R 808 0.3. 43 top
29062 root 20 0 1241 m 227 m 10 m S 0.3. 32 java
1 root 15 0 10368 684 S 572 0.0. 85 init
2 root RT-5 0 0 S 0.0 0.0. 01 migration/0
3 root 34 19 0 0 S 0.0 0.0. 00 ksoftirqd/0
4 root RT-5 0 0 S 0.0 0.0. 00 watchdog/0
5 root RT-5 0 0 S 0.0 0.0. 80 migration/1
6 root 34 19 0 0 S 0.0 0.0. 00 ksoftirqd/1
7 root RT-5 0 0 S 0.0 0.0. 00 watchdog/1
8 root RT-5 0 0 S 0.0 0.0. 59 migration/2
9 root 34 19 0 0 S 0.0 0.0. 09 ksoftirqd/2
10 root RT-5 0 0 0 S 0.0 0: 00. 00 watchdog/2
11 root RT-5 0 0 S 0.0 0.0. 66 migration/3
12 root 34 19 0 0 S 0.0 0.0. 03 ksoftirqd/3
13 root RT-5 0 0 S 0.0 0.0. 00 watchdog/3
14 root RT-5 0 0 S 0.0 0.0. 29 migration/4
15 root 34 19 0 0 S 0.0 0.0. 07 ksoftirqd/4
16 root RT-5 0 0 S 0.0 0.0. 00 watchdog/4
17 root RT-5 0 0 S 0.0 0.0. 07 migration/5
18 root 34 19 0 0 S 0.0 0.0. 07 ksoftirqd/5
19 root RT-5 0 0 S 0.0 0.0. 00 watchdog/5
20 root RT-5 0 0 S 0.0 0.0. 16 migration/6
21 root 34 19 0 0 S 0.0 0.0. 05 ksoftirqd/6
22 root RT-5 0 0 S 0.0 0.0. 00 watchdog/6
23 root RT-5 0 0 S 0.0 0.0. 28 migration/7
Top command output details:
Statistical information area:
The first five lines are the overall statistical information area of the current system. Next we will look at the specific meaning of each line of information.
The first line is the task queue information, which is the same as the execution result of the uptime Command. the specific parameters are described as follows:
14:06:23-current system time
Up 70 days, 16: 44-the system has been running for 70 days, 16 hours, and 44 minutes (during this period, the system has not restarted the restart !)
2 users-there are currently two users logging on to the system
Load average: 1.15, 1.42, 1.44-load average, the three numbers after which are 1 minute, 5 minutes, and 15 minutes respectively.
The load average data checks the number of active processes every five seconds and then calculates the value based on a specific algorithm. If this number is divided by the number of logical CPUs, the system is overloaded when the result is higher than 5.
Line 2: Tasks-task (process). The details are described as follows:
The system now has a total of 206 processes, of which one is running, 205 are sleep, 0 are stoped, and 0 are zombie.
The third line shows the cpu status information. the specific attributes are described as follows:
5.9% us-percentage of CPU used by user space.
3.4% sy-percentage of CPU occupied by kernel space.
0.0% ni-percentage of CPU used by processes with changed priorities
90.4% id-percentage of idle CPU
0.0% percentage of CPU occupied by wa-IO wait
0.0% hi-percentage of CPU used by Hardware IRQ
0.2% CPU usage of si-soft interrupt (Software Interrupts)
Note: Here, the CPU usage rate is different from that of windows. you need to understand the knowledge of linux user space and kernel space!
The fourth line shows the memory status. The details are as follows:
32949016 k total-total physical memory (32 GB)
14411180 k used-total memory in use (14 GB)
18537836 k free-total idle memory (18 GB)
169884 k buffers-cache memory (169 MB)
The fifth line, swap partition information, the specific information is described as follows:
32764556 k total-total swap zone (32 GB)
0 k used-total used Swap Zone (0 K)
32764556 k free-total number of idle swap areas (32 GB)
3612636 k cached-total buffer swap zone (3.6 GB)
Note:
In row 4, the total memory used (used) refers to the number of memories currently controlled by the system kernel. The total idle memory (free) is the amount of memory that the kernel has not yet incorporated into its control scope. The memory included in the kernel management is not always in use, but also the memory that can be reused in the past, the kernel does not return the reusable memory to free. therefore, free memory will become fewer and fewer on linux, but you don't have to worry about it.
If you calculate the number of available memory out of habit, there is an approximate formula: free in the fourth row + buffers in the fourth row + cached in the fifth row, according to this formula, the available memory of this server is about 18537836 k + 169884 k + 3612636 k = 22 GB.
For memory monitoring, we need to monitor the used of the fifth-line swap partition in top. if this value is constantly changing, it means that the kernel is constantly exchanging data between memory and swap, this is the real insufficient memory.
The sixth line is empty.
Row 7: monitors the status of each process (task). the Project column information is described as follows:
PID-process id
USER-Process Owner
PR-process priority
NI-nice value. A negative value indicates a high priority, and a positive value indicates a low priority.
VIRT-total virtual memory used by the process, in kb. VIRT = SWAP + RES
RES-physical memory used by the process, not swapped out, in kb. RES = CODE + DATA
SHR-shared memory size, in kb
S-process status. D = non-disruptive sleep state R = Running S = sleep T = tracking/stopping Z = botnets
% CPU-percentage of CPU time occupied since the last update
% MEM-percentage of physical memory used by the process
TIME +-total cpu time used by the process, in the unit of 1/100 seconds
COMMAND-process name (COMMAND name/COMMAND line)
Other tips:
1. Multi-U multi-core CPU monitoring
In the top basic view, press the keyboard number "1" to monitor the status of each logical CPU:
Observe that the server has 16 logical CPUs, which are actually 4 physical CPUs. Press the number key 1 to return to the top basic view interface.
2. highlight the current running process
Press "B" on the keyboard (enable/disable the highlight effect). The top view changes as follows:
We found that the "top" process with process id 2570 is highlighted, and the top process is the only running process shown in the second row of the view, you can press the "y" key to close or enable the brightening effect of running processes.
3. process field sorting
By default, processes are sorted by CPU usage. java processes with a process ID of 28894 rank first (cpu usage of 142% ), java processes with a process ID of 574 rank second (cpu usage: 16% ).
Press "x" on the keyboard (turn on/off the highlight effect of the sorting column). The top view changes as follows:
As you can see, the default sorting column of top is "% CPU ".
4. you can use "shift +>" or "shift + <" to change the sorting column to the right or left.
The view is sorted by % MEM according to "shift +>.
Instance 2: displays the complete command
Command: top-c
Output:
Instance 3: Display program information in batch mode
Command: top-B
Instance 4: Displays program information in accumulate mode
Command: top-S
Instance 5: set the number of information updates
Command: top-n 2
Note: The update display is terminated after two updates.
Instance 6: Set the information update time
Command: top-d 3
Note: The update period is 3 seconds.
Instance 7: displays the specified process information
Command: top-p 574
Output:
5. top interactive commands
Interactive commands that can be used during top command execution. These commands are single-letter. if the s option is used in the command line, some of these commands may be blocked.
H. The help screen is displayed, and some brief command summary is provided.
K. terminate a process.
I ignore idle and dead processes. This is a switch-on command.
Q. exit the program.
R reschedule the priority of a process
Switch S to accumulative mode
S changes the delay time between two refreshes (unit: s). if there is a decimal number, it is converted to m s. If the input value is 0, the system will be refreshed continuously. the default value is 5 s.
F or F: add or delete a project from the current display.
O or O changes the order of projects displayed
L switch to display average load and startup time information
M Switch display memory information
T switch displays process and CPU status information
C Switch display command name and complete command line
M is sorted by resident memory size
P sort by CPU usage percentage
T sort by time/accumulative time
W write the current settings ~ /. Toprc file