Linux memory monitoring is one of the most important resources managed by Linux kernel. The memory management system is the most important part of the operating system, because the physical memory of the system is always less than the amount of memory required by the system. Virtual Memory is the strategy used to overcome this conflict. By sharing memory among processes, the system's virtual memory seems to have more memory than the actual memory.
(1) Linux memory monitoring: monitors memory usage in real time
Use the "Free" command on the command line to monitor memory usage
- #free
- total used freeshared bufferscached
- Mem:256024192284 63740 0 10676101004
- -/+ buffers/cache: 80604175420
- Swap: 522072 0522072
The above shows a 256 mb ram and a 512 MB swap space system. The third row of output (Mem :) displays the physical memory. The total column does not display the core physical memory (usually about 1 MB ). The used column shows the total memory used (the second row does not count as a buffer ). The free column shows all unused memory. The Shared column displays the total memory Shared by multiple processes. The Buffers column displays the current disk cache size. The information displayed on the fifth line (Swap :) is similar to the above. If the behavior is 0, no swap space is used. By default, the free command displays memory usage in kilobytes (that is, 1024 bytes. Available? The h Parameter displays memory usage in bytes, or can it be used? The m parameter displays memory usage in MB. Can also pass? The s parameter uses commands to continuously monitor memory usage:
# Free? B? S2
This command continuously reports memory usage in the terminal window and updates every 2 seconds.
(2) Linux memory monitoring combo watch? The free command is used to monitor memory usage in Real Time:
- #watch -n 2 -d free
- Every 2.0s: freeFri Jul 6 06:06:12 2007
- total used freeshared bufferscached
- Mem:233356218616 14740 0 5560 64784
- -/+ buffers/cache:148272 85084
- Swap: 622584 6656615928
The watch command runs free once every two seconds. The screen is cleared before execution and data is displayed in the same position. Because the watch command does not scroll the screen, it is suitable for monitoring memory usage for a long time. You can use the-n option to control the execution frequency. You can also use the-d option to display commands in different places each time. The Watch command is executed until you press [Ctrl]-[C.