905

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

From the blog article of Understanding memory usage on Linux, ps is not an accurate tool to use for this intent.

Why ps is "wrong"

Depending on how you look at it, ps is not reporting the real memory usage of processes. What it is really doing is showing how much real memory each process would take up if it were the only process running. Of course, a typical Linux machine has several dozen processes running at any given time, which means that the VSZ and RSS numbers reported by ps are almost definitely wrong.

(Note: This question is covered here in great detail.)

4
  • 11
    This question probably belongs on serverfault.com instead nowadays, although it's telling me it's "too old to migrate". Don't actually want to close it though... Dec 21, 2012 at 0:11
  • Refer to this question. stackoverflow.com/questions/669438/…
    – Bloodmoon
    Jul 22, 2013 at 15:57
  • 4
    Actually ps doesn't show even that -- it shows virtual and resident memory numbers, where virtual is maximum amount of memory the process could theoretically use it it were the only process (never so), used every single page it allocated (never happens) and didn't map or unmap any pages (unlikely). While resident shows how much virtual memory is mapped to physical right now. Typically virt > usage > res however on a 64-bit system virt ~= res*10 it's a very wide range. Dec 14, 2015 at 8:55
  • 9
    The excerpt from the linked article is total nonsense. The RSS is physical memory actually used, and the VSZ may or may not translate to physical memory use even if the process was the only one running. May 14, 2017 at 1:25

32 Answers 32

1
2
0

I found heaptrack much easier to use than valgrind.

sudo apt install heaptrack heaptrack_gui
heaptrack my-program args
heaptrack_gui *.zst

heaptrack_gui snapshot

-2

Use the in-built System Monitor GUI tool available in Ubuntu.

1
  • 1
    At least since 16.04 that works very well. It's very much like top though, the memory used is not extremely precise... Jul 15, 2016 at 22:38
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.