Linux system monitoring command top

The most commonly used performance analysis tool in Linux displays the system resource usage in real time, similar to the Windows Task Manager

Process information item contents:

  • PID: Indicates the process ID
  • USER – USER that the process belongs to
  • PR – Process priority
  • NI – Nice value. A negative value indicates a high priority, and a positive value indicates a low priority
  • VIRT (Virtual Memory Usage) – Total amount of virtual memory used by a process (unit: KB). VIRT=SWAP+RES
  • Resident Memory Usage (RES) – The size of physical memory used by a process, in KB, that has not been paged out. RES=CODE+DATA
  • Shared memory (SHR) – Shared memory size (unit: KB)
  • S – Process status. D= uninterruptible sleep state R= run S= sleep T= track/stop Z= zombie process
  • %CPU – The CPU time usage percentage since the last update
  • %MEM – The percentage of physical memory used by processes
  • TIME+ – Total CPU TIME used by processes, expressed in 1/100 second
  • COMMAND – Process name (COMMAND name/COMMAND line)

Top Usage

top [-] [d] [p] [q] [c] [C] [S] [s] [n]

Parameter description:

  • D: Specifies the interval between each screen information refresh. Of course, the user can use the S interactive command to change it.
  • P: Monitors only the status of a process by specifying the process ID.
  • Q: This option will cause top to refresh without any delay. If the calling program has superuser privileges, then top will run at the highest possible priority.
  • S: specifies the accumulation mode.
  • S: Enables the top command to run in safe mode. This removes the potential dangers of interactive commands.
  • I: Make top not show any idle or dead processes.
  • C: Displays the entire command line, not just the command name.

When the top is running, you can run the following command to control the display

  • S Change the screen update frequency
  • L Turns on or off the representation of the top information in the first line of part 1
  • T Turns off or on the representation of the Tasks and %Cpus information in the second line and third line of the first part
  • M Turns on or off the representation of the Mem information in line 4 and Swap information in line 5 of part 1
  • N Processes are listed in the order of PID size
  • P Processes are listed in order of CPU usage
  • M Lists processes in order of memory usage
  • H Display help
  • N Set the number of processes to be displayed in the process list
  • Q out top
  • Ctrl+L: Erase and rewrite the screen
  • K: Terminate a process. The user will be prompted for the PID of the process to be terminated and what signals to send to the process. Generally, 15 signals can be used to terminate a process; If not, use signal 9 to force the process to end. The default value is signal 15. In safe mode, this command is masked.
  • I: Ignore idle and zombie processes. This is an on-off command.
  • R: Rearranges the priority of a process. The system prompts you to enter the PID and priority of the process to be changed. Entering a positive value will lower the priority, and vice versa will give the process higher priority. The default value is 10.
  • S: Switch to cumulative mode.
  • S: Change the delay between refreshes. The system prompts the user to enter a new time in seconds. If you have decimals, you convert it to m s. If you enter the value 0, the system will refresh continuously. The default value is 5 seconds. It is important to note that if you set the time too small, you will likely cause repeated refreshes, and you will not be able to see the display at all, and the system load will be greatly increased.
  • F or F: Adds or removes items from the current display.
  • O or O: Change the order in which items are displayed
  • L: Switch to display the average load and startup time.
  • M: Switches to display memory information.
  • C: Switches to display the command name and complete command line.
  • M: sorting by resident memory size.
  • P: sort by CPU usage percentage.
  • T: Sorted by time/cumulative time.
  • W: Writes the current Settings to the ~/.toprc file.

Control output details about the multi-core CPU

Enter 1 in the top command to display information about all CPU cores

Mpstat -p ALL and SAR -p ALL

Note: SAR -p ALL > aaa. TXT redirects the output to file aaa. TXT

System processes

  • To highlight a running process, enter b. To disable or turn on the highlight effect of a running process, enter y.

  • Enter x (turn on/off the highlighting effect of the sorting sequence), the default sorting of top is “%CPU”

  • Shift + > or shift + < allows you to change the sequence to the right or left

  • Another interface can be entered through F

    This interface lists all process fields that can be displayed in the top basic view. Fields with * and marked with uppercase letters are displayed. Fields without * and marked with lowercase letters are not displayed. To display fields “CODE” and “DATA” in the base view, enter r and s

Linux other commonly used performance query commands

# = total number of nuclear physics cpus X per physical CPU of nuclear # to the total number of logical CPU number X = physical CPU each physical CPU kernel number X hyper-threading # to check the number of physical CPU cat/proc/cpuinfo | grep "physical id |" Sort | uniq | wc - l # to check the number of each physical CPU core (nuclear) cat/proc/cpuinfo | grep "CPU cores" | uniq # to check the number of logical CPU cat/proc/cpuinfo | Grep "processor" | wc - l # to check the CPU information (models) cat/proc/cpuinfo | grep name | the cut - f2 - d: | uniq - c # cat/proc/meminfo memory informationCopy the code