System Performance Monitoring-Linux top commands

Source: Internet
Author: User
Tags 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. Such? The front-end executes this command, and it will exclusively occupy the front-end 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 sort tasks by CPU usage, memory usage, and execution time. 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.

TOP command syntax:
Top [-] [d delay] [Q] [C] [s] [s] [I]

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, top runs 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 command column of the Process displays the corresponding command line or command name of the process)

Detailed description of TOP command results:

The top command displays many items. The default value is to update every 5 seconds. The displayed items are:

15:06:57 up 129 days, 5 Users, load average: 1.21, 1.20, 1.25

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

222 processes: 219 sleeping, 2 running, 1 zombie, 0 stopped

Total number of processes running since the last refresh. These processes are divided into running, sleep, and stopped processes.

CPU states: CPU user nice system IRQ softirq iowait idle
Total 0.9% 0.0% 27.4% 0.0% 0.0% 0.2% 71.2%
Cpu00 1.9% 0.0% 19.4% 0.0% 0.0% 0.0%
Cpu01 0.0% 0.0% 33.0% 0.0% 0.0% 0.0%
Cpu02 1.9% 0.0% 22.3% 0.0% 0.0% 0.9% 74.7%
Cpu03 0.0% 0.0% 35.2% 0.0% 0.0% 0.0%

CPU States displays the percentage of CPU time used in various situations, such as user mode, system mode, priority process (only those with a negative priority), and idle. 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: 16214336 k av, 15682832 K used, 531504 K free, 0 K shrd, 215016 K buff
10896844 k actv, 3379680 K in_d, 446432 K in_c

Mem memory usage statistics, including the total available memory, idle memory, used memory, shared memory and cache memory.

Swap: 10482404 k av, 0 K used, 10482404 K free 14856500 K cached

Swap swap space statistics, including the total swap space, available swap space, and used swap space.

PID user pri Ni size RSS share stat % CPU % mem time CPU command

27869 root 25 0 460 m 460 m 455 M r 25.0 2.9 12559 M 1 vmware-vmx
31819 root 16 0 6016 6016 5048 s 1.6 0.0 17573 M 2 magicdev
27837 root 15-10 460 m 460 m 455 m s <0.7 2.9 1328 M 0 vmware-vmx
27868 root 15-10 460 m 460 m 455 m s <0.3 2.9 644: 35 3 vmware-vmx

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.

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

Top interactive Command Options

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.

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


//////////////

Linux memory management is similar to Windows Memory Management. It uses virtual memory. But why does pagefile still be used when Windows still has a large amount of physical memory? So we often have to argue with a group of people about the size of pagefile and how to allocate it, in Linux, there is no need to argue about the swap size. a m swap is generally enough. If it is small, you can consider adding a block of memory, check whether your application has a memory leak.

In Linux, we usually use command free to view memory.

[root@nonamelinux ~]# freetotal used free shared buffers cachedMem: 386024 377116 8908 0 21280 155468-/+ buffers/cache: 200368 185656Swap: 393552 0 393552

The following is an explanation of these values:

Row 2 (MEM ):

Total: total physical memory size.

Used: used.

Free: available.

Shared: The total memory shared by multiple processes.

Buffers/cached: disk cache size.

Row 3 (-/+ buffers/cached ):

Used: used.

Free: available.

The fourth line won't be explained much.

Differences:

The difference between used/free of the second row (MEM) and used/free of the third row (-/+ buffers/cache.

The difference between the two is that from the usage perspective, the second line is from the OS perspective, because for OS, buffers/cached is used, so its available memory is 8908kb, the used memory is kb, including the + buffers + cached used by the kernel (OS) + application (x, Oracle, etc.

The third line indicates that, from the application perspective, for applications, buffers/cached is equivalent to available, because buffer/cached is designed to improve file read performance, when the application needs to use the memory again, the buffer/cached will be quickly recycled.

From the application perspective, the available memory = system free memory + buffers + cached.

For example:

185656 = 8908 + 21280 + 155468

Next we will explain when the memory will be exchanged and how it will be exchanged.

When the available memory is less than the rated value, the switch starts.

Rating (rhel4.0 ):

# Cat/proc/meminfo

Switching reduces the number of physical pages used in the system in three ways:

1. Reduce the buffer and page cache size,

2. swap out the V-type memory page of the system,

3. Swap out or discard the page. (The Memory Page occupied by the application, that is, the physical memory is insufficient ).

In fact, using swap in a small amount affects the system performance.

The following is the difference between buffers and cached.

Buffers is the buffer size for Block devices. It only records the metadata and tracking in-flight pages of the file system.

Cached is used to buffer files.

That is to say: buffers is used for storage. What content and permissions are contained in the directory.

Cached is used directly to remember the files we opened. If you want to know whether the files take effect, you can try and execute two commands one by one # Man X, you can obviously feel that the second start is much faster.

Experiment: it is obvious on a machine with no application. Remember that the experiment can only be performed once. If you want to do more, change the file name.

#free#man X#free#man X#free

You can compare the size of buffers after free.

Another experiment:

#free#ls /dev#free

You can compare the two sizes. Of course, this buffers is increasing at any time, but if you have used ls, the increase speed will become faster. This is the difference between buffers and chached.

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.