日期:2014-05-16  浏览次数:20631 次

Linux: How to measure actual memory usage of an application or process?

http://stackoverflow.com/questions/131303/linux-how-to-measure-actual-memory-usage-of-an-application-or-process

?

Hi,

How do you measure the memory usage of an application or process in Linux? I've read?here?that "ps" is not an accurate tool to use for this intent.

Thanks, Kenneth

?

With?ps?or similiar tools you will only get the amount of memory pages allocated by that process. This number is correct, but:

a) does not reflect the actual amount of memory used by the application, only the amount of memory reserved for it

b) can be misleading if pages are shared, for example by several threads or by using dynamically linked libraries

If you really want to know what amount of memory your application actually uses, you need to run it within a profiler. For example,?valgrind?can give you insights about the amount of memory used, and, more importantly, about possible memory leaks in your program.

?

In recent versions of linux, use the?smaps?subsystem. For example, for a process with a PID of 1234: