-   Programming (
-   -   How to get the memory usage of myself process (GetProcessMemoryInfo() 4 linux)? (

faristol 04-22-2009 07:39 AM

How to get the memory usage of myself process (GetProcessMemoryInfo() 4 linux)?

I need to know the virtual memory usage, the page faults, and other memory related information in a linux/c++ program.

I need it to be posix-portable so I would try to avoid reading /proc/self/stat or /proc/self/statm because it is kernel/platform dependent.

In windows there's a function GetProcessMemoryInfo(), and GlobalMemoryStatus() which are pretty good for that.

Is there something similar in c/c++/linux?



rriggs 04-23-2009 01:53 PM

Check the getrusage(2) manpage but note the caveats.

faristol 04-24-2009 09:41 AM

Thanks rriggs!

That's just the thing that I was looking for :).

Now I've the issue that I when I call getrusage(), the structure is filled with 0, except for two fields, that already have wrong values :(.

I'm using RHEL 5.3 distro, and ldd for my program (procstat) tells me:
ldd procstat => /lib64/ (0x0000003ab0000000)
/lib64/ (0x0000003aafc00000)

and my already points to

Also tested the function mallinfo from malloc.h, and the problem was the same. It compile, but in the runtime it fills the structure with zero values.

Any ideas?

All times are GMT -5. The time now is 01:29 AM.