Linux commands: TOP

Source: Internet
Author: User

The top command is a common performance analysis tool under Linux that shows the resource usage of individual processes in the system in real time, similar to the Task Manager for Windows. Here is a detailed description of how it is used.

Top-02:53:32 up + days, 6:34, users, load average:0.24, 0.21, 0.24
tasks:481 Total, 3 running, 474 sleeping, 0 stopped, 4 zombie
Cpu (s): 10.3%us, 1.8%sy, 0.0%ni, 86.6%id, 0.5%wa, 0.2%hi, 0.6%si, 0.0%st
mem:4042764k Total, 4001096k used, 41668k free, 383536k buffers
swap:2104472k Total, 7900k used, 2096572k free, 1557040k cached

  PID user      PR   ni  virt  res  SHR S%cpu%mem    time+  COMMAND
32497 jacky  & nbsp;  20   0  669m 222m  31m r   10  5.6  29:27.62 firefox
4788 yiuwing& nbsp;  20   0  257m  18m  13m s    5  0.5   5:42.44 konsole< br>5657 liuxiaof  20   0  585m 159m  30m s    4  4.0   5:25.06 Fir Efox
4455 xiefc     20   0  542m 124m  30m r    4  3.1& nbsp;  7:23.03 Firefox
6188 liuxiaof  20   0  191m  17m  13m S    4   0.5   0:01.16 konsole
 


The first five elements of the statistical information area are the statistical information of the whole system. The first line is the task queue information, with the execution result of the uptime command. The contents are as follows:

01:06:48 Current Time
Up 1:22 system run time, format last: minutes
1 user Current number of users logged on
Load average:0.06, 0.60, 0.48 system load, which is the average length of the task queue.
The three values were 1 minutes, 5 minutes, and 15 minutes ago to the present average.


The second to third behavior process and CPU information. When there are multiple CPUs, the content may be more than two lines. The contents are as follows:

tasks:29 Total Process Totals
1 running number of running processes
Sleeping the number of sleep processes
0 Number of processes stopped stopped
0 Zombie Number of zombie processes
CPU (s): 0.3% US user space consumes CPU percentage
1.0% SY core space CPU percent occupied
0.0% CPU Percentage of processes that have changed priority within NI user process space
98.7% ID Idle CPU percent
0.0% wa wait for the input output CPU time percentage
0.0% hi
0.0% si


The last two behavior memory information. The contents are as follows:

MEM:191272K Total Physical Memory
Total physical memory used by 173656k used
17616k free Memory Total
The amount of memory that 22052k buffers uses as the kernel cache
Total swap area of swap:192772k
Total swap area used by 0k used
192772k Free Swap Area total
123988k cached Buffers The total number of swap areas.
The in-memory content is swapped out to the swap area and then swapped in to memory, but the used swap area has not been overwritten.
This value is the size of the swap area where the content already exists in memory.
When the corresponding memory is swapped out again, it is no longer necessary to write to the swap area.


The details of each process are shown below the process information area statistics area. Let's start by understanding the meaning of the columns.

Ordinal column name meaning
A PID process ID
b PPID Parent Process ID
C ruser Real User name
D UID Process Owner's user ID
e username of user process Owner
Group name of the F group Process owner
The terminal name of the G TTY boot process. Processes that are not started from the terminal are displayed as?
H PR-Priority
I NI nice value. Negative values indicate high priority, positive values indicate low priority
The last CPU used by J P is meaningful only in a multi-CPU environment
K%cpu CPU time consumption percentage last updated to current
The total CPU time, in seconds, used by the timing process
The total CPU time used by the M time+ process, in units 1/100 seconds
n the percentage of physical memory used by the%MEM process
o The total amount of virtual memory used by the VIRT process, in kilobytes. Virt=swap+res
The P swap process uses the size of the virtual memory, which is swapped out, in kilobytes.
The size of the physical memory, in kilobytes, that the Q RES process uses and has not been swapped out. Res=code+data
R code executable code occupies the physical memory size, in kilobytes
The amount of physical memory that is used outside of the S data executable code (data segment + stack), in kilobytes
T SHR shared memory size, in kilobytes
U Nflt page Error count
V NDRT the number of pages that have been modified in the last write to now.
W S Process state.
D = Non-interruptible sleep state
R = Run
S = Sleep
T = trace/Stop
Z = Zombie Process
x command name/command line
Y Wchan If the process is sleeping, the system function name in sleep is displayed
Z Flags task Flag, reference sched.h


By default, only the more important PID, USER, PR, NI, VIRT, RES, SHR, S,%cpu,%MEM, time+, and COMMAND columns are displayed. You can change the display by using the following shortcut keys.
Change the display by using the F key to select what to display. Press the F key to display a list of columns, press A-Z to show or hide the corresponding column, and then press ENTER to confirm.
Press the O key to change the order in which the columns are displayed. A-Z in the lower case moves the corresponding column to the right, while the uppercase A-Z moves the corresponding column to the left. Finally, press ENTER to confirm.
Press the uppercase F or O key, and then press A-Z to sort the process by the appropriate column. The uppercase R key can reverse the current sort.

==============================

While the top command is in use, you can also use some interactive commands to complete the functionality of other parameters. These commands are started by using shortcut keys.
Space: Refresh now.
P: Sort According to CPU usage size.
T: Sort by time, cumulative time.
Q: Exit the top command.
M: Toggles display memory information.
T: Toggles display of process and CPU status information.
C: Toggle display command name and full command line.
M: Sorts according to the size of the memory used.
W: Writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.

As you can see, the top command is a very powerful tool for monitoring systems and is especially important for system administrators. However, its disadvantage is that it consumes a lot of system resources.

Application examples
You can use the top command to monitor a specified user, and the default is to monitor processes for all users. If you want to view the situation of the specified user, press the "U" key in the terminal and enter the user name, the system will switch to the user's process run interface.

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.