First, Introduction
Top is a dynamic display process where the current state can be refreshed continuously with the user key. If the command is executed in the foreground, it will monopolize the foreground until the user terminates the program. More accurately, the top command provides real-time status monitoring of the system's processor. It will display the most "sensitive" CPU in the system. Task List. This command can be used by CPU. Memory usage and execution time to sort tasks, and many of the features of the command can be set through interactive commands or in personal customization files.
Ii. Common directives
H or? : Displays the help screen and gives a brief summary of the commands. K: terminates a process. The user will be prompted for the process PID to be terminated and what signal needs to be sent to the process. The normal termination process can use a 15 signal, and if not, use signal 9 to force end the process. The default value is signal 15. This command is masked in safe mode. I: Ignore idle and zombie processes. This is a switch-type command. Q: Quit the program. R: Reschedule the priority level of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value that needs to be set. Entering a positive value lowers the priority and, conversely, it gives the process a higher priority. The default value is 10. S: switch to cumulative mode. S: Change the delay time between two refreshes. The user will be prompted to enter a new time in S. If there are decimals, it is converted into Ms. Enter a value of 0 and the system will refresh continuously, the default value is 5 S. It is important to note that if you set too small a time, it is likely to cause a constant refresh, so it is too late to see the display, and the system load will be greatly increased. F/F: Add or remove items from the current display. o/o: Change the order in which items are displayed. L: Toggle display of average load and start time information. That is to show the shadow of the first row m: Toggle display memory information. The Shadow Memory line T: Toggles display of process and CPU status information. The Shadow CPU line C: Toggle Displays the command name and the full command line. Displays the complete command. This feature is useful. M: Sorts based on the size of the resident memory. P: Sorts according to the percentage size of CPU usage. T: Sort by Time / cumulative time. W: Writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.
Third, examples
1) Find the thread with high CPU usage:
PS H-eo User,pid,ppid,tid,time,%cpu,cmd--sort=%cpu
2) View the process that consumes the highest CPU
Top (then press p, note that this is uppercase) PS aux| Head -1; PS aux| grep -v pid| sort -rn-k +4| Head
3) View the most memory-intensive processes
Top (then press m, note that this is uppercase) PS aux| Head -1; PS aux| grep -v pid| sort -rn-k +3| Head
Reference: http://www.jb51.net/LINUXjishu/34604.html
Linux Top Command