Linux - Detailed top command (monitoring process and overall performance of Linux)

top startup parameters

  • top: Run the basic top command to display all process information, refresh every 5 seconds, and sort according to the usage percentage %CPU
  • top -c: show the entire command line instead of the entire command name
  • top -d secs: Indicates the process interface update time (5 seconds by default)
  • top -n max: the number of times to cycle through the display
  • top -u|U user: Specify username information
  • top -p pid(s) : View the specified process information
  • top -b: Batch file mode, used together with the "n" parameter, can be used to output the results of top to a file
  • top -o field: According to which column to sort, such as sorting according to memory top -o %MEM(top uses cpu to sort by default)
  • top -w [cols]: Display the details of a column
  • top -q:top is refreshed without any delay.
  • top -S: Specifies the accumulation mode
  • top -s: Make the top command run in safe mode. Potential dangers posed by interactive commands will be removed.
  • top -i: Make top not show any idle or dead processes.
  • top -b -n 2 > /tmp/top.txt: Indicates that the process table with PID 2 is printed twice in /tmp/top.txt.

Basic field description

Old street cat.

The first line, system task statistics:

top - 16:55:08 up 194 days,  1:23,  1 user,  load average: 0.00, 0.01, 0.05
  • 16:55:08- current system time
  • up 194 days, 1:23- The system has been running for 194 days, 1 hour and 23 minutes (no reboot during this period)
  • 1 user- There is currently a user logged into the system
  • load average: 0.00, 0.01, 0.05- The latter three are the average system load from 1 minute, 5 minutes, and 15 minutes ago to the present, and the converted percentages are 0%, 1%, and 5%.

The second line, process statistics:

Tasks:  75 total,   1 running,  74 sleeping,   0 stopped,   0 zombie

Tasks (processes): There are currently 75 processes in the system, of which 1 is running, 74 are dormant, 0 are in the stopped state, and 0 are in the zombie state

  • X total: total number of processes
  • X running: number of running processes
  • X sleeping: Number of sleeping processes
  • X stopped: number of processes stopped
  • X zombie: number of zombie processes

The third line, CPU statistics:

%Cpu(s):  1.0 us,  0.7 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

CPU usage percentage: 1% for user, 0.7% for kernel, 0.0% for process with changed priority, 98.3% for idle, 0.0% for IO waiting, 0.0% for hard interrupt, 0.0% for soft interrupt, stolen 0.0% of

  • X us: The percentage of CPU consumed by the user mode process
  • X sy: Percentage of CPU consumed by the kernel
  • X ni: Percentage of CPU occupied by processes whose priority has been changed in the user process space
  • X id: Percentage of idle CPU
  • X wa: CPU percentage consumed by IO read and write waiting
  • X hi: CPU percentage consumed by hardware interrupts (Hardware IRQ)
  • X si: CPU percentage consumed by soft interrupts (Software IRQ)
  • X st: Stolen CPU percentage
    Note:
    IRQ: The full name of IRQ is Interrupt Request, which means "interrupt request".
    st: Abbreviation of stole time, this indicator is only valid for virtual machines, indicating the percentage of CPU time allocated to the current virtual machine that is stolen by other virtual machines on the same physical machine

The fourth line, memory statistics:

KiB Mem :  1883724 total,    78476 free,   623420 used,  1181828 buff/cache

Memory/KIB: The total amount of physical memory is 1883724kib=1.796G, the free memory is 78476kib=76M, the memory in use is 623420kib=608M, and the amount of cached memory is 1181828kib=1.127G: Total physical memory - total memory
X kib totalin
X kib useduse
X kib free- Total free memory
Xkib buff/cache- Amount of cached memory

The fifth line, swap swap partition statistics:

KiB Swap:        0 total,        0 free,        0 used.  1055252 avail Mem

Swap partition/KiB: the total amount of swap area is 0, the total amount of free swap area is 0, the total amount of used swap area is 0, and the total amount of available swap area is 1055252Kib=1.006G - total amount of swap area - total amount of swap
X kib totalarea
X kib usedused Amount
X kib free- Total Free Swap
X kib avail Mem- Total Available Swap

Note:
For memory monitoring, you must always monitor the used of the swap partition on the fifth line in top. If this value is constantly changing, it means that the kernel is constantly exchanging data between memory and swap, which means that the memory is not enough.

The sixth line, process information

PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
  • PID: process id
  • USER: process owner
  • PR: Process priority
  • NI: nice value. Negative values ​​indicate high priority, positive values ​​indicate low priority
  • VIRT: virtual memory usage Virtual memory
    1. The virtual memory size "needed" by the process, including the library, code, data, etc. used by the process. 2.
    If the process applies for 100m of memory, but actually only uses 10m, then it will increase by 100m, and not actual usage
  • RES: resident memory usage resident memory
    1. The memory size currently used by the process, but not including swap out
    2. Including the sharing of other processes
    3. If you apply for 100m of memory and actually use 10m, it will only increase by 10m, contrary to VIRT
    4. Regarding the memory occupied by the library, it only counts the memory size occupied by the loaded library files
  • SHR: shared memory Shared memory
    1. In addition to the shared memory of its own process, it also includes the shared memory of other processes
    2. Although the process only uses a few functions of the shared library, it includes the size of the entire shared library
    3. Calculate a certain process The physical memory size formula: RES – SHR
    4, after swap out, it will drop down
  • DATA
    1. The memory occupied by the data. If top is not displayed, press the f key to display it.
    2. The real data space required by the program is actually used during operation.
  • S: Process status. D=uninterruptible sleep R=running S=sleep T=trace/stop Z=zombie process
  • %CPU: The percentage of CPU time occupied since the last update
  • %MEM: Percentage of physical memory used by the process
  • TIME+: The total CPU time used by the process, unit 1/100 second
  • COMMAND: process name (command name/command line)

control interface display

In the top running interface, press the following buttons (case sensitive):

  • 1– Show all CPU usage
  • s– Change the screen update frequency
  • l– Turn off or turn on the display of top information on the first line
  • t– Turn off or turn on the second line of Tasks and the third line of Cpus information display
  • m– Turn off or turn on the display of the fourth line of Mem and the fifth line of Swap information
  • N– Arrange the process list in the order of PID size
  • P– Sort the process list in order of CPU usage
  • M– Arrange the process list in order of memory usage
  • h– show help
  • n– Set the number of processes displayed in the process list
  • q– exit top

Add undisplayed fields

By default, only the important PID, USER, PR, NI, VIRT, RES, SHR, S, %CPU, %MEM, TIME+, COMMAND columns are displayed. You can use the following shortcut keys to change the display content: after
pressing the key , and press the key . Example: 1. Enter the interface where the top command is running 2. Press 3. Move the mouse to PPID (parent process id) 4. Press the button to select, and the number will be displayed on the front after selection 5. Press the button to exit, and you can see that PPID is added behind Listf空格Esc


Old street cat.
f
Old street cat.

Old street cat.
空格PPUD*
Old street cat.
Esc
Old street cat.

Detailed field description

Process thread:

  • PID: process id
  • PPID: parent process id
  • PGRP: process group id
  • PR: Process priority
  • TPGID: Tty process group id
  • TGID: thread group id
  • WCHAN: If the process is sleeping, display the name of the system function in sleep

User related :

  • UID: The user id of the process owner (that is, the displayed identity may not be the real identity)
  • USER: The username of the process owner
  • RUID: real user id
  • RUSER: real user name
  • SUID: saved user id
  • SUSER: saved username
  • GID: effective user group id
  • GROUP: The group name of the process owner
  • SID: session id (that is, it can be said to be a user session, or a session of a process)
  • CGROUPS: control group
  • SUPGIDS: support group ID

Memory resources:

  • CODE: The physical memory size occupied by the executable code, in kb
  • DATA: The size of physical memory occupied by parts other than executable code (data segment + stack), in kb
  • RES: The physical memory size used by the process and not swapped out, in kb. RES=CODE+DATA, corresponding to the %MEM column.
  • SHR: Shared memory or library size. unit kb
  • SWAP: The swapped-out size of the virtual memory used by the process, in kb.
  • USED: RES + SWAP size, unit kb.
  • VIRT: The total amount of virtual memory used by the process, in kb. VIRT=SWAP+RES

CPU resources:

  • TIME: The total CPU time used by the process, in seconds
  • TIME+: The total CPU time used by the process, the unit is 1/100 second, for example, the format of the CPU time corresponding to 5:29.38 is: minutes:seconds.hundredths
  • %CPU: CPU usage
  • P: The last CPU used, only meaningful in a multi-CPU environment

characteristic:

  • S: Process status. (D=uninterruptible sleep state, R=running, S=sleep, T=trace/stop, Z=zombie process)
  • NI: Nice value friendliness, negative value means high priority, positive value means low priority
  • COMMAND: process name or command line started (switched by c command)
  • ENVIRON:environment variable
  • TTY: The name of the terminal that started the process. Processes not started from a terminal are displayed as ?

Statistical data:

  • nTH: Number of Threads number of threads
  • nDRT: The number of pages that have been modified since the last write
  • nFLT: number of page faults
  • nMaj: The requested memory page has not been loaded yet, this is the request generated by the main application memory application
  • nMin: The memory page is loaded but not managed by the MMU
  • namespace: as a means of resource isolation for a group of processes
  • nsIPC: IIPC namespace, used to isolate IPC
  • nsMNT: for isolating mount points
  • nsNET: Used to isolate the network stack
  • nsPID: used to isolate the process number
  • nsUSER: Used to isolate users
  • nsUTS: Used to isolate domain name and hostname
  • Flags: task flag, refer to sched.h
  • vMj: major page fault count increment
  • vMn: minor page fault count increment

Guess you like

Origin blog.csdn.net/weixin_44988085/article/details/128646171