How can I measure the actual memory usage of an application or process?

后端 未结 30 2739
心在旅途
心在旅途 2020-11-22 03:01

This question is covered here in great detail.

How do you measure the memory usage of an application or process in Linux?

From the blog articl

30条回答
  •  再見小時候
    2020-11-22 03:49

    If your code is in C or C++ you might be able to use getrusage() which returns you various statistics about memory and time usage of your process.

    Not all platforms support this though and will return 0 values for the memory-use options.

    Instead you can look at the virtual file created in /proc/[pid]/statm (where [pid] is replaced by your process id. You can obtain this from getpid()).

    This file will look like a text file with 7 integers. You are probably most interested in the first (all memory use) and sixth (data memory use) numbers in this file.

提交回复
热议问题