Linux top command

Source: Internet
Author: User
Tags terminates superuser permission
The basic functions of the top command and ps command are the same, displaying the current process of the system and other conditions. However, the top command is a dynamic display process, that is, you can press the key to continuously refresh the current state. If you execute this command on the foreground, it excludes the foreground until the user terminates the program. Comparison... information &


The basic functions of the top command and ps command are the same, displaying the current process of the system and other conditions. However, the top command is a dynamic display process, that is, you can press the key to continuously refresh the current state. 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-most "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. The command parameters and interactive commands will be described separately in the subsequent sections.
 
The syntax format of the command is as follows:
Top [-] [d delay] [q] [c] [s] [S]
D. specify the interval between two screen information refreshes. Of course, you can use the s interactive command to change it.
Q This option will refresh top without any delay. If the caller has the superuser permission, the top node will run 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.
The top command displays many items. the default value is updated every 5 seconds. of course, this can be set. The displayed items are:
Uptime indicates the system startup time, running time, and three average load values (the load values of the last 1 second, 5 seconds, and 15 seconds ).
Processes
 
Total number of processes running since the last refresh. Of course, these processes are divided into running, sleep, and stopped processes. Process and status display can be achieved through interactive command t.
 
CPU states
 
Displays the percentage of CPU time used by user mode, system mode, priority process (only those with a negative priority), idle, and other conditions. The time consumed by the priority process is also included in the user and system time, so the total percentage will be greater than 100%. Mem memory usage statistics, including the total available memory, idle memory, used memory, shared memory and cache memory.
Swap space statistics, including the total Swap space, available Swap space, and used Swap space.
Pid id of each process.
PPID: the parent process ID of each process.
UID: the UID of each process owner.
USER: The username of each process owner.
The priority of each process in PRI.
The priority of the process.
SIZE: the code SIZE of the process, the data SIZE, and the total SIZE of the stack space. The unit is KB.
TSIZE: the code size of the process. This is a strange value for kernel processes.
DSIZE data and stack size.
TRS text resident size.
D. The page project marked as "not clean.
The size of the library page used by LIB. It does not work for the ELF process.
RSS the total number of physical memory occupied by the process, in KB.
SHARE the amount of memory used by the process.
STAT the status of the process. S indicates the sleep state, D indicates the non-interrupted sleep state, R indicates the running state, Z indicates the frozen state, and T indicates the stopped or tracked state.
TIME the total cpu time occupied by the process since it was started. If you enter the accumulative mode, the time also includes the time occupied by the sub-process of the process. The title is changed to CTIME. % CPU the percentage of CPU time and total time occupied by the process since the last refresh. % MEM the percentage of physical memory occupied by the process to the total memory.
COMMAND indicates the COMMAND name of the process. if one line does not show any more, the COMMAND is intercepted. The process in the memory has a complete command line.
 
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.
<空格> ; Refresh the display immediately.
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 ms. 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.
From the above introduction, we can see that the top command is a powerful tool for monitoring the system, especially for system administrators. Generally, users may think that the ps command is actually enough, but the powerful features of the top command indeed provide a lot of convenience. Next let's take a look at the actual usage.
 
[Example] enter the top command to view the system status
$ Top
Pm up 7 min, 4 user, load average: 0.07, 0.09, 0.06
29 processes: 28 sleeping, 1 running, 0 zombie, 0 stopped
CPU states: 4.5% user, 3.6% system, 0.0% nice, 91.9%
Idle
Mem: 38916 K av, 18564 K used, 20352 K free, 11660 K shrd,
1220 K buff
Swap: 33228 K av, 0 K used, 33228 K free, 11820 K cached
Pid user pri ni size rss share stat lib % CPU % MEM TIME
COMMAND
363 root 14 0 708 708 552 R 0 8.1 1.8 0: 00 top
1 root 0 0 404 404 344 S 0 0.0 0: 03 init
2 root 0 0 0 0 SW 0 0.0 0.0 kflushd
3 root-12-12 0 0 0 SW <0 0.0 0.0 kswapd
4 root 0 0 0 0 SW 0 0.0 0.0 md_thread
5 root 0 0 0 0 SW 0 0.0 0.0 0: 00 md_thread
312 root 1 0 636 636 488 S 0 0.0 0: 00 telnet
285 root 6 0 1140 1140 804 S 0 0.0 2.9 bash
286 root 0 0 1048 1048 792 S 0 0.0 2.6 bash
25 root 0 0 364 364 312 S 0 0.0 0.9 kerneld
153 root 0 0 456 456 372 S 0 0.0 1.1 syslogd
160 root 0 0 552 552 344 S 0 0.0 1.4 klogd
169 daemon 0 0 416 416 340 S 0 0.0 1.0 atd
178 root 2 0 496 496 412 S 0 0.0 1.2 crond
187 bin 0 0 352 352 284 S 0 0.0 0.9 portmap
232 root 0 0 500 500 412 S 0 0.0 1.2 rpc. mountd
206 root 0 0 412 412 344 S 0 0.0 1.0 inetd
215 root 0 0 436 436 360 S 0 0.0 1.1 icmplog
 
The projects in the first line are the current time, system startup time, number of users logged on to the current system, and average load.
The second behavior process is the total number of processes, the number of dormant processes, the number of running processes, the number of dead processes, and the number of terminated processes.
The CPU status of the third action is user usage, system usage, priority process usage, and idle process usage.
The fourth act is the memory status, which is the average available memory, used memory, idle memory, shared memory, and cache memory.
The fifth behavior switching status is average available switching capacity, used capacity, idle capacity, and high-speed cache capacity. The following is a list of processes that are similar to ps. In general, the top command is more powerful than ps, but it takes a long time to occupy the foreground. Therefore, you should use this command according to your own situation.

Author: ERDP technical architecture"

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.