How to use the top command in linux

Source: Internet
Author: User
Top commands are often used to monitor linux system conditions, such as cpu and memory usage. Programmers generally know this command, but it is strange that few people can use it well, for example, the memory value in the top monitoring View has many misinterpretations. This article uses a running WEB server t...
Top commands are often used to monitor linux system conditions, such as cpu and memory usage. Programmers generally know this command, but it is strange that few people can use it well, for example, the memory value in the top monitoring View has many misinterpretations. This article describes the meaning of various data in the top view through top monitoring of a running WEB server, and sorts the fields of various processes (tasks) in the view. Top entry View top View 01 [top View 01] is the basic view of top. we will use this view to explain the meaning of each data.
The first line:
10:01:23 current system time
126 days, the system has been running for 126 days, 14 hours, and 29 minutes (during this period, the system has not restarted)
2 users currently has two users logging on to the system
Load average: 1.15, 1.42, and 1.44 load average are the loads of 1 minute, 5 minutes, and 15 minutes respectively. The load average data checks the number of active processes every five seconds and then calculates the value based on a specific algorithm. If this number is divided by the number of logical CPUs, the system is overloaded when the result is higher than 5.
Row 2:
Task Tasks (processes), the system now has a total of 183 processes, of which one is running, 182 are sleep, and 0 are stoped, zombie status (zombie) has 0.
Row 3: cpu status
6.7% us CPU usage percentage.
0.4% percentage of CPU occupied by sy kernel space.
0.0% percentage of CPU used by processes whose priorities have changed by ni
92.9% id idle CPU percentage
0.0% percentage of CPU occupied by wa IO wait
CPU usage of 0.0% hi Hardware interrupt (Hardware IRQ)
The CPU usage percentage of 0.0% si soft interrupt (Software Interrupts) is different from that of windows. if you do not understand the user space and kernel space, you need to be charged.
Row 4: Memory status
8306544 k total physical memory (8 GB)
Total memory used by 7775876 k used (7.7 GB)
530668 k free memory (530 MB)
79236 k buffers cache memory (79 M)
Row 5: swap partition
2031608 k total swap zone total (2 GB)
Total number of swap areas used by 2556 k used (2.5 M)
2029052 k free swap zone Total (2 GB)
4231276 k cached buffer swap zone (4 GB)
It should be noted that the concept of memory in windows cannot be used to understand the data. if the server is vulnerable in windows mode, the total memory size of 8 GB is limited to MB of available memory. Linux Memory management has its own particularity, and the complexity needs to be explained in a book. here is just a simple introduction and our traditional concepts (windows) are different.
In row 4, the total memory used (used) refers to the number of memories currently controlled by the system kernel. The total idle memory (free) is the amount of memory that the kernel has not yet incorporated into its control scope. The memory included in the kernel management is not always in use, but also the memory that can be reused in the past, the kernel does not return the reusable memory to free. therefore, free memory will become fewer and fewer on linux, but you don't have to worry about it. If you calculate the number of available memory out of habit, there is an approximate formula: free in the fourth row + buffers in the fourth row + cached in the fifth row, according to this formula, the available memory of this server is 530668 + 79236 + 4231276 = 4.7 GB.
For memory monitoring, we need to monitor the used of the fifth-line swap partition in top. if this value is constantly changing, it means that the kernel is constantly exchanging data between memory and swap, this is the real insufficient memory.
The sixth line is empty. the seventh line is as follows: status monitoring of each process (task)
PID process id
USER Process Owner
PR process priority
NI nice value. A negative value indicates a high priority, and a positive value indicates a low priority.
Total virtual memory used by the VIRT process, in kb. VIRT = SWAP + RES
The size of the physical memory used by the RES process, not swapped out, in kb. RES = CODE + DATA
Size of SHR shared memory, in kb
S process status. D = non-disruptive sleep state R = Running S = sleep T = tracking/stopping Z = botnets
% Percentage of CPU time used since the last CPU update to the present

% MEM percentage of physical memory used by the process
TIME + total cpu time used by the process, in the unit of 1/100 seconds
COMMAND process name (COMMAND name/COMMAND line) multi-U multi-core CPU monitoring in the top basic view, by keyboard number 1, you can monitor the status of each logical CPU:
Top view 02: The server has 16 logical CPUs, which are actually 4 physical CPUs. By default, process fields are sorted by CPU usage when they enter top, in [top View 01], java processes with process ID 14210 ranked first (cpu usage 100%), and java processes with process ID 14183 ranked second (cpu usage 12% ). You can use the keyboard command to change the sorting field. for example, if you want to monitor which process occupies the most MEM resources, you can use the following methods: 1. press the keyboard B (turn on/off the highlighted effect), and the top view changes as follows:
Top view 03 we found that the top process with the process id 10704 is highlighted, and the top process is the only running process shown in the second row of the view, you can press the y key to close or enable the brightening effect of running processes. 2. press the keyboard x (enable/disable the highlight effect of the sorting column). The top view changes as follows:
Top View 04: The default top sorting column is % CPU. 3. shift +> or shift + <可以向右或左改变排序列,是按一次shift +> Of:
The top View 05 is now sorted by % MEM. Change the process Display field 1. press the f key and top to enter another view. here, you can orchestrate the display field in the basic view:
Top View 06 lists all process fields that can be displayed in the top basic view. fields marked with uppercase letters are displayed, fields without letters * and lowercase letters are not displayed. To display the CODE and DATA fields in the basic view, you can press the r and s keys:
Top view 072. press enter to return to the basic view. we can see two more fields: CODE and DATA:
Top view top 10 command supplement top command is the first choice for system monitoring on Linux, but sometimes it does not meet our requirements. for example, the current server, top monitoring has great limitations. This server runs the websphere cluster and has two node services: the boss and the second java processes in [top View 01]. the smallest unit of top command monitoring is the process, therefore, I cannot see the number of java threads and the number of client connections that I care about. these two indicators are very important indicators of java web services. Generally, I use the ps and netstate commands to supplement the lack of top.
Number of java threads monitored:
Ps-eLf | grep java | wc-l number of network customer connections monitored:
Netstat-n | grep tcp | grep listening port | the two commands above wc-l can modify the grep parameter to meet more detailed monitoring requirements.
Under the guidance of the idea that everything in the Linux system is a file, all processes can run in a file. In the system root directory/proc, the name of each digital subdirectory is the PID of the running process. you can enter any process directory and observe the running indicators of the process through the files or directories, for example, the task directory is used to describe the threads in a process. Therefore, you can use the following method to obtain the number of threads running in a process (PID indicates the process ID ):
Ls/proc/PID/task | wc-l has a command pmap in linux to output the process memory status. it can be used to analyze the thread stack: pmap PID.
 
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.