问题描述
我认为我的LAMP应用程序中可能发生内存泄漏(内存用完了,交换开始用完了,等等).如果我可以看到各种进程使用了多少内存,则可以帮助我解决问题.有没有办法让我在* nix中查看此信息?
I think I may have a memory leak in my LAMP application (memory gets used up, swap starts getting used, etc.). If I could see how much memory the various processes are using, it might help me resolve my problem. Is there a way for me to see this information in *nix?
推荐答案
获得正确的内存使用情况比人们想象的要棘手.我可以找到的最佳方法是:
Getting right memory usage is trickier than one may think. The best way I could find is:
echo 0 $(awk '/TYPE/ {print "+", $2}' /proc/`pidof PROCESS`/smaps) | bc
过程"是您要检查的过程的名称,类型"是以下之一:
Where "PROCESS" is the name of the process you want to inspect and "TYPE" is one of:
-
Rss
:常驻内存使用率,该进程使用的所有内存,包括该进程与其他进程共享的所有内存.它不包括交换; -
Shared
:该进程与其他进程共享的内存; -
Private
:此过程使用的私有内存,您可以在此处查找内存泄漏; -
Swap
:交换进程使用的内存; -
Pss
:比例集大小,一个很好的整体内存指示器.为共享进行了Rss调整:如果一个进程在其他10个进程之间有1MiB专用和20MiB共享,则Pss为1 + 20/10 = 3MiB
Rss
: resident memory usage, all memory the process uses, including all memory this process shares with other processes. It does not include swap;Shared
: memory that this process shares with other processes;Private
: private memory used by this process, you can look for memory leaks here;Swap
: swap memory used by the process;Pss
: Proportional Set Size, a good overall memory indicator. It is the Rss adjusted for sharing: if a process has 1MiB private and 20MiB shared between other 10 processes, Pss is 1 + 20/10 = 3MiB
其他有效值为 Size
(即虚拟大小,几乎没有意义)和 Referenced
(当前标记为已引用或已访问的内存量)
Other valid values are Size
(i.e. virtual size, which is almost meaningless) and Referenced
(the amount of memory currently marked as referenced or accessed).
您可以使用watch
或其他bash-script-fu来监视要监视的进程的那些值.
You can use watch
or some other bash-script-fu to keep an eye on those values for processes that you want to monitor.
有关smaps
的更多信息: http://www.kernel. org/doc/Documentation/filesystems/proc.txt .
这篇关于在Linux中,如何判断正在使用多少内存进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!