Usage and analysis of TOP commands in Linux

Source: Internet
Author: User
Tags superuser permission
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, similar to the Windows Task Manager. The following describes how to use it. Top-01: 06: 48up1: 0.06 user, loadaverage: 0.60, 0.48, Tasks: 29 total, 1run

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, similar to the Windows Task Manager. The following describes how to use it.

Top-01:06:48 up, 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: 191272 k total, 173656 k used, 17616 k free, 22052 k buffers

Swap: 192772 k total, 0 k used, 192772 k free, 123988 k cached


Pid user pr ni virt res shr s % CPU % mem time + COMMAND

1379 root 16 0 7976 2456 S 1980 0.7. 03 sshd

14704 root 16 0 2128 980 R 796 0.7. 72 top

1 root 16 0 1992 632 S 544 0.0. 90 init

2 root 34 19 0 0 S 0.0 0.0. 00 ksoftirqd/0

3 root RT 0 0 0 S 0.0 0.0. 00 watchdog/0


The first five lines in the statistical information area are the overall statistical information of the system. The first line is the task queue information, which is the same as the execution result of the uptime Command. The content is as follows:

01:06:48 current time

Up system running time, format: minute

1 user current login user count

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.


Second and third, information about the process and CPU. When multiple CPUs exist, the content may exceed two rows. The content is as follows:

Tasks: 29 total process count

1. number of running processes of running

28 sleeping sleep processes

0 stopped process count

0 zombie botnets

Cpu (s): 0.3% us CPU usage

1.0% sy CPU usage in kernel space

0.0% percentage of CPU used by processes that have changed their priorities in ni user process space

98.7% id idle CPU percentage

0.0% wa CPU time percentage waiting for input and output

0.0% hi

0.0% si


Memory information of the last two behaviors. The content is as follows:

Mem: 191272 k total physical memory

Total physical memory used by 173656 k used

17616 k free memory total

Memory usage of 22052 k buffers as Kernel Cache

Swap: 192772 k total number of Swap areas

Total number of swap areas used by 0 k used

192772 k free swap zone total

The total number of swap areas of the 123988 k cached buffer.

The content in the memory is swapped out to the swap zone and then into the memory, but the used swap zone has not been overwritten,

This value indicates the size of the swap zone where the content already exists in the memory.

When the corresponding memory is swapped out again, you do not have to write data to the swap zone.


Detailed information about each process is displayed at the bottom of the process information area. First, let's take a look at the meaning of each column.

Serial number 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

GROUP name of the owner of the f GROUP process

The terminal name of the g TTY startup process. Processes not started from the terminal are displayed?

H PR priority

I NI nice value. A negative value indicates a high priority, and a positive value indicates a low priority.

The final CPU used by j P is only meaningful in multiple CPU environments

K % Percentage of CPU time used since the last CPU update to the present

L total cpu time used by the TIME process, in seconds

M TIME + the total cpu time used by the process, in the unit of 1/100 seconds

N % MEM percentage of physical memory used by the process

O total virtual memory used by the VIRT process, in kb. VIRT = SWAP + RES

The SWAP size in the virtual memory used by the p SWAP process, in kb.

The size of the physical memory used by the q RES process, not swapped out, in kb. RES = CODE + DATA

The physical memory occupied by the r CODE executable CODE, in kb.

Physical memory occupied by other parts (DATA segment + stack) except the executable code of s DATA, in kb

T SHR shared memory size, in kb

U nFLT page error count

The number of modified pages that the last write to the present by v.

W S process status.

D = uninterrupted sleep

R = run

S = sleep

T = tracking/stopping

Z = Zombie process

X COMMAND name/COMMAND line

Y WCHAN: if the process is sleep, the system function name in sleep is displayed.

Z Flags task flag, refer to sched. h


By default, only important PID, USER, PR, NI, VIRT, RES, SHR, S, % CPU, % MEM, TIME +, and COMMAND columns are displayed. You can use the shortcut keys below to change the display content.

You can use the f key to change the display content. Press f to display the column list. press a-z to display or hide the corresponding column, and press enter to confirm.

Press the o key to change the column display sequence. A lower-case a-z can move the corresponding column to the right, while an upper-case A-Z can move the corresponding column to the left. Press Enter.

Press the F or O key in upper case, and then press a-z to sort the process according to the corresponding column. The uppercase R key can reverse the current sorting.

Command usage

1. tool (command) name

Top

2. Functions of tools (commands)

Displays the current process and other conditions of the system. top is a dynamic display process, which allows you to refresh the current state by pressing the buttons. 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.

3. environment settings

In Linux.

4. usage

4.1 Format

Top [-] [d]


[Q] [c] [C] [S] [s] [n]

4.2 parameter description

D. specify the interval between two screen information refreshes. Of course, you can use the s interactive command to change it.

P only monitors the status of a process by specifying the monitoring process ID.

Q This option will refresh top without any delay. If the caller has the superuser permission, top runs with the highest possible priority.

S indicates the accumulative mode.

S enables the top command to run in safe mode. This removes the potential danger of interactive commands.

I so that top does not show any idle or dead processes.

C. display the entire command line, not just the command name.

4.3 Others

The following describes some interactive commands that can be used during top command execution. From the perspective of usage, mastering these commands is more important than mastering the options. These commands are single-letter. if the s option is used in the command line option, some of these commands may be blocked.

Ctrl + L erase and override the screen.

H or? The help screen is displayed, and some brief command summary is provided.

K. terminate a process. The system prompts the user to enter the PID of the process to be terminated and the signal to be sent to the process. Generally, 15 signals can be used to terminate a process. if the process cannot end normally, use signal 9 to forcibly end the process. The default value is signal 15. This command is blocked in security mode.

I ignore idle and dead processes. This is a switch-on command.

Q: exit the program.

R reschedules the priority of a process. The system prompts the user to enter the process PID to be changed and the process priority value to be set. Entering a positive value will lower the priority, and vice versa will give the process a higher priority. The default value is 10.

S switches to the accumulative mode.

S changes the delay time between two refreshes. The system prompts the user to enter a new time in seconds. 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. It should be noted that if the setting is too small, it is likely to cause constant refresh, so it is too late to see the display, and the system load will increase significantly.

F or F: add or delete a project from the current display.

O or O changes the order of projects displayed.

L switching displays average load and startup time information.

The m switch displays the memory information.

T switch displays the process and CPU status information.

C switch to display the command name and complete command line.

M is sorted based on the resident memory size.

P is sorted by CPU usage percentage.

T is sorted by time/accumulative time.

W write the current settings ~ /. Toprc file. This is a recommended method for writing top configuration files.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.