"Linux" System Tools Top

Source: Internet
Author: User
Tags terminates

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 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.

    1. Command format: top [parameters]
    2. Command function: Displays information about the processes currently being executed by the system, including process ID, memory usage, CPU utilization, etc.
    3. Command parameters:
      • -B batch processing for easy record history
      • -C Displays the complete ruling command
      • -I ignores the failure process
      • -S Secret mode
      • -s cumulative mode, not statistics at refresh interval
      • -D < time > set interval time
      • -U < username > Specify user name
      • -p < Process number > Specify process
      • -N < times > number of cycles displayed
    4. Usage examples:
Example 1: Displaying process information

Command: Top

Output:

[[email protected]]# toptop-14:06:23 up], 16:44, 2 users, load average:1.25, 1.32, 1.35tasks:206 total,  1 running, 205 sleeping, 0 stopped, 0 zombiecpu (s): 5.9%us, 3.4%sy, 0.0%ni, 90.4%id, 0.0%wa, 0.0%hi, 0.2%si, 0.0%stmem:32949016k Total, 14411180k used, 18537836k free, 169884k buffersswap:32764556k total, 0k used, 32764                                                                556k free, 3612636k cached PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND                                                                   28894 Root 0 1501m 405m 10m S 52.2 1.3 2534:16 Java                                                                    18249 Root 0 3201m 1.9g 11m S 35.9 6.0 569:39.41 Java                                                                    2808 Root 0 3333m 1.0g 11m S 24.3 3.1 526:51.85 Java 25668 Root 0 3180m 704m 11m S 14.0 2.2 360:              44.53 Java                                                       574 Root 0 3168m 611m 10m S 12.6 1.9 556:59.63 Java 1599 Root 0 3237m 1.9g 11m S 12.3 6.2 262:01.1 4 Java 1008 root 0 3147m 842m 10m S 0.3 2. 6 4:31.08 Java 13823 root 0 3031m 2.1g 10m S 0.3 6.8 176:57.34 Java 28218 root 15 0 12760   1168 808 R 0.3 0.0 0:01.43 top 29062 Root 20 0 1241m 227m 10m S 0.3 0.7 2:07.32 Java 1 roo                                                                       T 0 10368 684 572 S 0.0 0.0 1:30.85 Init 2 Root RT-5    0 0 0 S 0.0 0.0 0:01.01 migration/0 3 root                                                                0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0                                                                 4 root RT-5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0                                                                5 root RT-5 0 0 0 S 0.0 0.0 0:00.80 MIGRATION/1                                                                6 Root 0 0 0 S 0.0 0.0 0:00.00 KSOFTIRQD/1                                                                 7 Root RT-5 0 0 0 S 0.0 0.0 0:00.00 WATCHDOG/1                                                                8 root RT-5 0 0 0 S 0.0 0.0 0:20.59 MIGRATION/2                           9 Root 0 0 0 S 0.0 0.0 0:00.09 KSOFTIRQD/2                                    Root RT-5 0 0 0 S 0.0 0.0 0:00.00 WATCHDOG/2                                                               Root RT-5 0 0 0 S 0.0 0.0 0:23.66 MIGRATION/3 Root 0 0 0 S 0.0 0.0 0:00.03 KSOFTIRQ D/3 Root RT-5 0 0 0 S 0.0 0.0 0:00.0 0 WATCHDOG/3 Root RT-5 0 0 0 S 0.0 0. 0 0:20.29 MIGRATION/4 Root 34 19 0 0 0    S 0.0 0.0 0:00.07 KSOFTIRQD/4 root RT-5 0  0 0 S 0.0 0.0 0:00.00 WATCHDOG/4 Root RT -5 0 0 0 S 0.0 0.0 0:23.07 MIGRATION/5 Root 34 19 0 0     0 S 0.0 0.0 0:00.07 KSOFTIRQD/5 Root RT-5      0 0 0 S 0.0 0.0 0:00.00 WATCHDOG/5 Root                                                               RT-5 0 0 0 S 0.0 0.0 0:17.16 MIGRATION/6                                                               Root 0 0 0 S 0.0 0.0 0:00.05 KSOFTIRQD/6                                                                Root RT-5 0 0 0 S 0.0 0.0 0:00.00 WATCHDOG/6 Root RT-5 0 0 0 S 0.0 0.0 0:58.28 MIGRATION/7

Description:

Statistical information area: The first five elements is the current system of the overall statistical information area. Let's look at the specific meaning of each line of information. The first line, the task queue information, and the execution result of the uptime command, the specific parameters are as follows: 14:06:23-current system time up to 70 days, 16:44-the system has been running for 16 hours and 44 minutes (during which the system has not restarted the Yo!). 2 users-currently has 2 users logged into the system load average:1.15, 1.42, 1.44-load average the three numbers are 1 minutes, 5 minutes, 15 minutes of load respectively. The load average data is the number of active processes that are checked every 5 seconds and then calculated by a particular algorithm. If this number is divided by the number of logical CPUs, the result above 5 indicates that the system is overloaded. The second line, tasks-task (process), the specific information is described as follows: The system now has 206 processes, of which there are 1 running, 205 in hibernation (sleep), 0 in the stoped state, and 0 in the zombie State (zombie). The third line, CPU status information, the specific properties are described as follows: 5.9%us-the percentage of CPU occupied by user space. 3.4% sy-The percentage of CPU consumed by the kernel space. 0.0% ni-Change the priority of the process to occupy the percentage of CPU 90.4% id-Idle CPU percent 0.0% Wa-io waiting for CPU percentage 0.0% hi-hard Interrupt (Hardware IRQ)% of CPU 0.2% si-soft interrupt (so Ftware interrupts) Percentage of CPU Usage Note: In this case the CPU utilization ratio and the Windows concept are different, need to understand Linux system user space and kernel space knowledge! The four-line, memory state, specific information is as follows: 32949016k total-total Physical Memory (32GB) 14411180k used-total Memory in use (14GB) 18537836k free-total free memory (18GB) 169884k buffers-Cache Memory (169M) line fifth, swap swap partition information, specific information is described as follows: 32764556k total-swap Area total (32GB) 0k used-Total swap area (0K) 32764556k free-free Swap area total (32GB) 3612636k cached-buffer swap area total (3.6GB) Note: The total amount of memory used in line fourth (used) refers to the current system core controlThe amount of free memory that the kernel has not yet included in its control range. The memory that is included in kernel management is not always in use, but also includes the memory that has been used in the past that can now be reused, and the kernel does not return these reusable memory to free, so there is less memory on Linux, but don't worry about it. If you are accustomed to calculating the number of available memory, here is an approximate formula: The fourth line of Free + fourth row buffers + fifth row of cached, according to this formula this server's available memory: 18537836k +169884k +3612636k = 22GB or so. For memory monitoring, in the top we have to monitor the fifth line swap partition used, if this value is constantly changing, indicating that the kernel is constantly in memory and swap data exchange, which is really not enough memory. * * Line sixth, blank line. Line seventh below: status monitoring of each process (task), the project column information is described as follows: pid-process iduser-Process owner pr-process priority Ni-nice value. A negative value represents a high priority, and a positive value represents the total amount of virtual memory used by the low-priority virt-process, in kilobytes. The size, in kilobytes, of the physical memory used by the virt=swap+resres-process and not swapped out. res=code+datashr-Shared memory size, unit kbs-process state. d= non-disruptive sleep state r= run s= sleep t= track/stop z= zombie process%cpu-Last update to current CPU time consumption percentage%mem-process uses the percentage of physical memory time+-process uses CPU time total, unit 1/100 seconds command-process name Call (command name/command line)
Other tips for use:
    • Multi-u multicore CPU monitoring in the top basic view, press the keypad number "1" to monitor the status of each logical CPU:

Observe that the server has 16 logical CPUs, which are actually 4 physical CPUs. Press the number key 1 again to return to the top basic view interface.

    • Highlight the current running process hit keyboard "B" (Turn on/off the highlight effect), top of the view changes as follows:

We found that the "top" process with process ID 2570 was highlighted, and the top process was the only running state (runing) that was shown in the second row of the view, and you could turn off or turn on the highlight of the running process by tapping the "Y" key.

    • Process field sort By default, the processes are sorted by CPU consumption, with the process ID 28894 being the first Java process (CPU consuming 142%) and the second (CPU consuming 16%) of the Java process with process ID 574.

Hit the keyboard "X" (The highlight effect on/off the sorting sequence), the top view changes as follows: You can see that the top default sort column is "%cpu".

    • With SHIFT + > or SHIFT + <, you can change the sort order to the right or left by pressing SHIFT + >, and the view is now sorted by%mem.

    • Select the background or statistic color by "Z" and "B" to select Bold

Top Interactive Commands

Some of the interactive commands that you can use during the top command execution. These commands are single-letter, and some of these commands may be masked if the S option is used on the command line.

    • H Display the help screen and give some brief command summary instructions
    • K Terminates a process.
    • I ignore idle and zombie processes. This is a switch-type command.
    • Q Exit Program
    • R reschedule a process's priority level
    • S Switch to cumulative mode
    • s change the delay time between two refreshes (in units of s), and if there are decimals, convert to M S. Enter 0 value and the system will refresh continuously, the default value is 5 s
    • F or F Add or remove items from the current display
    • such as: Top display swap utilization, use the top command after the F key, and then press the P key, enter after the swap status can be seen
    • O or O change the order in which items are displayed
    • L Toggle display of average load and start-up time information
    • M Toggle Display Memory Information
    • T toggle display of process and CPU status information
    • C Toggle Display command name and full command line
    • M[Capital]: Sort based on the size of the resident memory
    • P[Capital]: Sort by CPU percent size
    • T[Capital]: Sort by time/cumulative time
    • H[caps]: Show threads,
    • W[Capital]: Writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files

Common:

C: Toggle display command name and full command line 1 (number 1): List all individual CPU load conditions z:top display color p[uppercase]: List program by CPU high and low order m[uppercase]: List program X in high and low order of memory: similar highlighting, the effect will be more obvious in Z display mode
Reference:

One Linux command per day: Top command

Top Practice Tips

"Linux" System Tools Top

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.