在 Linux 中,如何判断进程使用了​​多少内存? [英] In Linux, how to tell how much memory processes are using?

查看:34
本文介绍了在 Linux 中,如何判断进程使用了​​多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的 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

其中PROCESS"是您要检查的进程的名称,TYPE"是其中之一:

Where "PROCESS" is the name of the process you want to inspect and "TYPE" is one of:

  • Rss:常驻内存使用量,该进程使用的所有内存,包括该进程与其他进程共享的所有内存.不包括掉期;
  • Shared:该进程与其他进程共享的内存;
  • Private:本进程使用的私有内存,可以在这里查找内存泄漏;
  • Swap:交换进程使用的内存;
  • Pss:Proportional Set Size,一个很好的整体记忆指标.它是为共享调整的 Rss:如果一个进程有 1MiB 私有和 20MiB 在其他 10 个进程之间共享,则 Pss 是 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.

For more informations about smaps: http://www.kernel.org/doc/Documentation/filesystems/proc.txt.

这篇关于在 Linux 中,如何判断进程使用了​​多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆