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.
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)
.
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.
Can anybody confirm whether using RSS
value will point to the amount of memory leak in the code? Or is there any other method?
I know this is ancient, but I feel the need to say that for something like this, you really just want to use a tool like Valgrind. Namely, Valgrind. That's definitely the way to go, especially with a program you're writing (or have written), since you can tweak the compile flags as well so you can get the most useful output. Assuming you're using
gcc
, try compiling with-g
to turn on debug symbols and don'tstrip
the binary.Usage is pretty simple, and the docs are on the linked website. Basic usage is just
valgrind program
on the command line. It'll show you not only specifics, but a nice summary of memory leaked at the end.To know the details you can use pmap: pmap pid
I use top for this sort of thing.