linux top

Introduction

The top command is a commonly used performance analysis tool under Linux. It can display the resource occupancy status of each process in the system in real time, similar to the Windows task manager.

top displays the current process and other status of the system. It is a dynamic display process, that is, the current status can be continuously refreshed through the user's keystrokes. If the command is executed in the foreground, it will occupy the foreground until the user terminates the program. More precisely The ,top command provides real-time monitoring of the system's processor status. It will display a list of the most "sensitive" tasks for the CPU in the system. The command can sort tasks by CPU usage, memory usage, and execution time; and the command's Many features can be set through interactive commands or in personal customization files.

The following describes its use in detail.
Parameter meaning
Copy code

top - 01:06:48 up 1:22, 1 user, load average: 0.06, 0.60, 0.48
Tasks: 29 total, 1 running, 28 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.3% us, 1.0% sy, 0.0% ni, 98.7% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 191272k total, 173656k used, 17616k free, 22052k buffers
Swap: 192772k total, 0k used, 192772k free, 12398 cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1379 root 16 0 7976 2456 1980 S 0.7 1.3 0:11.03 sshd
14704 root 16 0 2128 980 796 R 0.7 0.5 0:02.72 top 132 94
0 S 19 0.0 0.3 0:00.90 init
2 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/

0


information. The first line is the task queue information, which is the same as the execution result of the uptime command. Its content is as follows:

01:06:48 Current time
up 1:22 System running time, format: hour: minute
1 user Current number of logged-in users
load average: 0.06, 0.60, 0.48 System load, that is, the average length of the task queue. The three values ​​are the average values ​​from 1 minute, 5 minutes, and 15 minutes ago to the present.



The second and third behaviors are information about the process and CPU. These may exceed two lines when there are multiple CPUs. The content is as follows:
copy code

total The total number
of processes running The number of running processes
sleeping The number of sleeping processes
stopped The number of stopped processes zombie The number of
zombie processes The percentage of CPU occupied by the process whose priority has been changed within 98.7% id The percentage of idle CPU 0.0% wa The percentage of CPU time waiting for input and output 0.0% hi: The percentage of hardware CPU interrupt usage 0.0% si: The percentage of soft interrupt usage 0.0% st: The percentage of virtual machine usage Percentage Copy code The last two lines are memory information. The content is as follows: Mem: 191272k total total physical memory 173656k used total physical memory used 17616k free total free memory 22052k buffers memory used as kernel cache Swap: 192772k total total swap area 0k used used swap area Total 192772k free Total free swap area




























123988k The total amount of swap area buffered by cached, the content in the memory is swapped out to the swap area, and then swapped into the memory, but the used swap area has not been overwritten, this value is the amount of content that already exists in the memory. The size of the swap area, when the corresponding memory is swapped out again, it is not necessary to write to the swap area.

Copy code The detailed information of each process is displayed below the statistics area of ​​the



process information area. First, let's understand the meaning of each column.
Copy code

No. Column name Meaning
a PID process id
b PPID parent process id
c RUSER Real user name
d UID user id of the
process owner e USER user name of the
process owner f GROUP group name of the process owner
g TTY terminal where the process was started name. Processes not started from the terminal are displayed as ?
h PR priority
i NI nice value. Negative value means high priority, positive value means low priority
j P The last CPU used, only meaningful in multi-CPU environment
k % CPU    last update to the present CPU time occupancy percentage
l TIME Total CPU time used by the process, Unit second
m TIME+ Total CPU time used by the process, unit 1/100 second
n %MEM    The percentage of physical memory used by the process
o The total amount of virtual memory used by the VIRT process, in kb. VIRT=SWAP+RES
p In the virtual memory used by the SWAP process, the size that is swapped out, in kb.
q The size of the physical memory used by the RES process and not swapped out, in kb. RES=CODE+DATA
r CODE Physical memory size occupied by executable code, unit kb
s DATA Physical memory size occupied by parts other than executable code (data segment + stack), unit kb
t SHR Shared memory size, unit kb
u nFLT Page faults
v nDRT The number of pages that have been modified since the last time the DRT was written.
w S Process state (D=uninterruptible sleep state, R=running, S=sleep, T=trace/stop, Z=zombie process)
  COMMAND command name/command line
y WCHAN If the process is sleeping, display sleep System function name in
z Flags Task flags, refer to sched.h to

copy the code


By default , only the more important PID, USER, PR, NI, VIRT, RES, SHR, S, %CPU, %MEM, TIME+, COMMAND columns are displayed . The display content can be changed by the shortcut keys below.

Change the display content The f key can select the display content. After pressing the f key, a list of columns will be displayed, press az to show or hide the corresponding column, and finally press the Enter key to confirm.
Press the o key to change the order in which the columns are displayed. Press lowercase az to move the corresponding column to the right, and uppercase AZ to move the corresponding column to the left. Finally press Enter to confirm.
Press the uppercase F or O key, then az to sort the processes by the appropriate column. The uppercase R key reverses the current sorting.

The command uses

top to use the format

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


Parameter description
Copy code

d Specify the time interval between every two screen information refreshes . Of course the user can use the s interactive command to change it.
p Monitor only the status of a process by specifying the monitor process ID.
q This option will make top refresh without any delay. If the calling program has superuser privileges, then top will run with the highest possible priority.
S Specifies cumulative mode
s to make the top command run in safe mode. This removes the potential danger posed by interactive commands.
i makes top not show any idle or zombie processes.
c Display the entire command line instead of just the command name

Copy code


Other useful commands
The following describes some interactive commands that can be used during the execution of the top command. From a usage point of view, mastering these commands is more important than mastering the options. These commands are all single letter, if the s option is used in the command line options, some of these commands may be blocked.
Copy code

Ctrl+L Erase and rewrite the screen.
h or ? Displays a help screen giving some brief command summaries.
k terminates a process. The system will prompt the user to enter the PID of the process that needs to be terminated, and what kind of signal needs to be sent to that process. The general termination process can use the 15 signal; if it cannot be terminated normally, use the signal 9 to force the termination of the process. The default value is signal 15. This command is blocked in safe mode.
i Ignore idle and zombie processes. This is a switch command.
q Quit the program.
r Reschedules the priority level of a process. The system prompts the user to input the process PID that needs to be changed and the process priority value that needs to be set. Entering a positive value will make the priority lower, otherwise it will make the process have a higher priority. The default value is 10.
S Switch to accumulation mode.
s Changes the delay time between refreshes. The system will prompt the user to enter a new time in seconds. If there is a decimal, it is converted to ms. If you enter a value of 0, the system will refresh continuously. The default value is 5 s. It should be noted that if the time is set too small, it is likely to cause continuous refresh, so that it is too late to see the display clearly, and the system load will be greatly increased.
f or F Add or remove items from the current display.
o or O Change the order of displayed items.
l Toggle to display the average load and startup time information.
m Toggles display of memory information.
t Toggles display of process and CPU status information.
c Toggles showing the command name and the full command line.
M is sorted by resident memory size.
P is sorted by CPU usage percentage size.
T is sorted by time/cumulative time.
W writes the current settings to the ~/.toprc file. This is the recommended way to write top configuration files.

Copy code



with common operations:

top //Display the resource usage of all processes every 5 seconds
top -d 2 //Display the resource usage of all processes every 2 seconds
top -c //Display the resource usage of all processes every 5 seconds, And display the command line parameters of the process (only the process name by default)
top -p 12345 -p 6789//Display the resource usage of the two processes with pid 12345 and pid 6789 every 5 seconds
top -d 2 -c -p 123456 //Display the resource usage of the process whose pid

is .
In the Linux environment, when it is found that the java process occupies a high amount of CPU resources, and you want to further find out which java thread occupies the CPU resources, follow the steps below to find out:
(1): Through [ top -p 12377 -H ] View the running status of the threads in the java process;
      and generate the dump details of the Java thread through [jstack 12377 > stack.log]; after the

PID is converted to hexadecimal, you can search for the thread in the thread stack dump file.



Reprinted from http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326689027&siteId=291194637