table of Contents
The top command provides the ability to monitor CPU-related data in real time
1. Command parameters
top [-] [d delay] [p pid] [q] [c] [C] [S] [s] [i] [n iter] [b] [u]
d
delay each refresh interval, in secondsSuch as: refresh top -d 2 every two seconds
p
pid process ip, you can use ps -ef to query related process information.top -p 123
q
Refresh without delayc
Display the entire command line instead of displaying the command nameC
Display overall CPU information, only valid for SMP systemS
Specify accumulation modes
Make the top command run in safe mode. This will remove the potential dangers caused by interactive commandsi
Make top not display any idle or dead processesn
iter specifies the number of iterative output of the top command, iter is the specific number of iterationsb
Run top in "Batch" mode. In this mode, all input from the terminal will be ignored (except ctrl+c of course). This parameter can be combined with the parameter "n" to run the specified number of iterations to exit or the process is killed. This is the default mode of running top output to dumb terminal or output to non-terminalu
Monitor processes owned by user user
2. Runtime command parameters
s
To change the screen update frequency, you need to enter the refresh frequency, such as 1sl
Turn off or turn on the display of the top information in the first line of the first partt
Turn off or turn on the representation of the second line of Tasks and the third line of CPU information in the first partm
Turn off or turn on the display of the Mem and Swap information in the fourth line and the fifth line in the first partN
Arrange and display the process list in the order of PID size (described later in Part 3)P
Arrange the process list in order of CPU usage (described later in Part 3)M
Arrange the process list in order of memory usage (described later in Part 3)h
Show helpn
Set the number of processes displayed in the process listq
Exit top
3. Output parameters
3.1 The first part of the system information bar
3.1.1 The first line (top)
top - 15:41:50 up 1 day, 23:08, 2 users, load average: 1.16, 1.61, 1.86
- 15:41:50 Current time
- 23:08 The running time of the system from the start to the present
- 2 users The number of users logging in to the system (the number of terminals)
- Load average The average value of the current system load. The next three values are the average number of processes 16 minutes ago, 61 minutes ago, and 86 minutes ago. Generally, it can be considered that when this value exceeds the number of CPUs, the CPU will be more difficult to load. Introduction to the load average of the processes included in the system
3.1.2 The second line (Tasks)
Tasks: 144 total, 2 running, 142 sleeping, 0 stopped, 0 zombie
- total The total number of processes in the current system
- running The number of currently running processes
- sleeping The number of processes currently in a waiting state
- stopped the number of processes stopped
- zombie zombie process number
3.1.3 The third line (Cpus)
%Cpu (s): 0.0 us, 3.2 sy, 3.2 ni, 93.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
- Respectively indicate the current utilization rate of the CPU
3.1.4 The fourth line (Mem)
KiB Mem : 7896532 total, 197976 free, 3937820 used, 3760736 buff/cache
- total running memory
- free amount of free memory
- used The amount of memory used
- buff/cache The amount of memory used as kernel cache
3.1.5 The fifth row (Swap)
KiB Swap: 0 total, 0 free, 0 used. 3700620 avail Mem
- total Total amount of swap partition memory
- free The amount of free memory in the swap area
- used The amount of memory used in the swap area
- avail Mem The amount of available memory in the swap area
- Usually the swap partition (Swap) is frequently used, it will be regarded as the result of insufficient physical memory
3.2 The second part of the process information
PID
Process identifierUSER
Process owner usernamePR/PRI
Priority of process executionNI
NICE value, negative value means high priority, positive value means low priorityVIRT
The total amount of virtual memory used by the process, in kb. VIRT=SWAP+RESRES
The size of the physical memory used by the process that has not been swapped out, in kb. RES=CODE+DATASHR
Shared memory size, unit kbS/STAT
Process status- D: Uninterruptible sleep state
- R: a process that is running or in a queue
- S: in sleep state
- T: stopped or tracked
- Z: Zombie process
- W: Enter memory swap
- X: dead process
%CPU
Percentage of CPU time from the last update to the present%MEN
Percentage of physical memory used by the processTIME+
The total CPU time occupied after the process is started, that is, the cumulative value of the occupied CPU time (unit 1/100s)COMMAND
The name of the command executed by the process
Four. CPU file
CPU file: /proc/cpuinfo
- Number of physical CPUs
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
- Number of CPU cores
cat /proc/cpuinfo| grep "cpu cores"| uniq
- Number of logical CPUs
cat /proc/cpuinfo| grep "processor"| wc -l
- View CPU information (model)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
Generally, logical CPU = number of physical CPUs * number of cores. If it is not equal, it means that the CPU supports hyper-threading technology (it can make one core in the processor play a role in the operating system like two cores. In this way, the operating system The available execution resources are doubled, which greatly improves the overall performance of the system. At this time, logical cpu=number of physical CPUs×number of each core x2)