Resident Set Size (RSS) from /proc/pid/stat
Thursday, January 22, 2009
Most UNIX-like systems have information about processes stored in /proc/pid/ files, so does Linux.
If you would want to get the Resident Set Size (RSS) of a process on Linux you could find this in a number of files:
- /proc/pid/stat: targetted for scanf(3)
- /proc/pid/statm: targetted for scanf(3) but just memory information (more detailed)
- /proc/pid/status: targetted at humans
Oddly enough if you check these three files for the RSS memory you will get different results! It seem both stat and statm have the wrong RSS information. It is a mystery to me why.
8 comments:
Marius Gedminas said...
The information is correct, the units are different. Both stat and statm show the resident set size in pages, while status shows it in kilobytes.
Unknown said...
Oh, how silly of me! But that would make sense.
Roger Pack said...
so I assume that's *1024 for the real number?
Unknown said...
Not always. You can get the pagesize in python by:
os.sysconf('SC_PAGESIZE')
And in C:
#include <unistd.h>
sysconf(_SC_PAGESIZE)
On my system I get 4096...
Roger Pack said...
what about the vmRSS from /status--*1024?
Thanks!
-=r
Unknown said...
indeed
Roger Pack said...
thanks
Chris Angelico said...
Easier way to get the page size:
$ getconf PAGESIZE
Quicker than whipping up a C program.
New comments are not allowed.