如何查找进程的内存泄漏? [英] How to find memory leaks of a process?

查看:207
本文介绍了如何查找进程的内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出特定进程的内存使用情况.实际上,我需要找出我编写的应用程序中是否存在内存泄漏.我无法使用memfree/proc/meminfo,因为我们的系统已在RAM中安装了日志文件夹.

I need to find out the memory usage of a particular process. In fact I need to find out there is any memory leak in the application I have written. I cannot use memfree or /proc/meminfo since our system has log folder mounted in the RAM.

我经历了很多类似的查询,并且有些建议使用ps aux命令.我对哪个参数可以正确使用内存或几个小时后出现内存泄漏感到困惑. PS AUX给出VSZ(virtual mem)RSS(resident set size).

I have gone through lot of similar queries, and some have suggested to use ps aux command. I’m kinda confused on which parameter gives the correct memory usage or maybe memory leak after few hours. PS AUX gives VSZ(virtual mem) and RSS(resident set size).

我编写了一个示例程序,该程序分配了4个字节的内存并将其取消分配.运行该程序后,分配内存时VSZ值似乎增加,而取消分配时VSZ值却没有减少.但是RSS值显示正确,分配时增加,取消分配时减少.

I have written a sample program which allocates 4 bytes of memory and De-allocates it. After running the program, it seems VSZ value increases when memory is allocated but not decreased when De-allocated. But RSS value showed correct, increases when allocated and decreased when De-allocated.

有人可以确认使用RSS值是否指向代码中的内存泄漏量吗?还是还有其他方法?

Can anybody confirm whether using RSSvalue will point to the amount of memory leak in the code? Or is there any other method?

推荐答案

要了解详细信息,可以使用pmap: pmap pid

To know the details you can use pmap: pmap pid

root@tm# pmap 1216
1216:   /usr/sbin/acpid
08048000     32K r-x--  /usr/sbin/acpid
08050000      4K rw---  /usr/sbin/acpid
08051000      4K rw---    [ anon ]
088f2000    140K rw---    [ anon ]
b7642000      4K rw---    [ anon ]
b7643000   1280K r-x--  /lib/i686/cmov/libc-2.11.3.so
b7783000      4K -----  /lib/i686/cmov/libc-2.11.3.so
b7784000      8K r----  /lib/i686/cmov/libc-2.11.3.so
b7786000      4K rw---  /lib/i686/cmov/libc-2.11.3.so
b7787000     12K rw---    [ anon ]
b7798000      8K rw---    [ anon ]
b779a000      4K r-x--    [ anon ]
b779b000    108K r-x--  /lib/ld-2.11.3.so
b77b6000      4K r----  /lib/ld-2.11.3.so
b77b7000      4K rw---  /lib/ld-2.11.3.so
bfd59000     84K rw---    [ stack ]
 total     1704K

这篇关于如何查找进程的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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