27

I have a system (Ubuntu) with many processes and one (or more) have a memory leak. Is there a good way to find the process that has the leak? Some of the process are JVMs, some are not. Some are home grown some are open source.

4

7 回答 7

15

You can run the top command (to run non-interactively, type top -b -n 1). To see applications which are leaking memory, look at the following columns:

  • RPRVT - resident private address space size
  • RSHRD - resident shared address space size
  • RSIZE - resident memory size
  • VPRVT - private address space size
  • VSIZE - total memory size
于 2008-09-27T15:25:27.003 回答
9

如果程序长时间泄漏,top 可能不实用。我会编写一个简单的 shell 脚本,每隔 X 秒将“ps aux”的结果附加到文件中,具体取决于泄漏大量内存所需的时间。就像是:

while true
do
echo "---------------------------------" >> /tmp/mem_usage
date >> /tmp/mem_usage
ps aux >> /tmp/mem_usage
sleep 60
done
于 2008-09-29T02:28:58.600 回答
6

我建议使用 htop,作为 top 的更好替代品。

于 2008-11-05T14:57:29.507 回答
5

如果你不能演绎地做到这一点,请考虑 Signal Flare 调试模式:将一个进程分配的内存量增加 10 倍。然后运行你的程序。

如果泄漏的内存量相同,则该进程不是泄漏源;恢复该进程并对下一个进程进行相同的修改。

当您点击负责的进程时,您会看到内存泄漏跳跃的大小(​​“信号耀斑”)。您可以通过有选择地增加此过程中单独语句的分配大小来进一步缩小范围。

于 2008-09-29T17:33:08.863 回答
5

除了顶部,您还可以使用系统监视器(系统 - 管理 - 系统监视器,然后选择进程选项卡)。选择查看 - 所有进程,转到编辑 - 首选项并启用虚拟内存列。按此列或按内存列排序

于 2008-09-27T16:56:15.427 回答
4

Difficult task. I would normally suggest to grab a debugger/memory profiler like Valgrind and run the programs one after one in it. Soon or later you will find the program that leaks and can tell it the devloper or fix it yourself.

于 2008-09-27T15:21:33.347 回答
3

As suggeseted, the way to go is valgrind. It's a profiler that checks many aspects of the running performance of your application, including the usage of memory.

Running your application through Valgrind will allow you to verify if you forget to release memory allocated with malloc, if you free the same memory twice etc.

于 2008-09-27T15:34:54.157 回答