LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to get the memory usage of myself process (GetProcessMemoryInfo() 4 linux)? (http://www.linuxquestions.org/questions/programming-9/how-to-get-the-memory-usage-of-myself-process-getprocessmemoryinfo-4-linux-720891/)

faristol 04-22-2009 06:39 AM

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

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?

Thanks

Rafa

rriggs 04-23-2009 12:53 PM

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

faristol 04-24-2009 08: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
libc.so.6 => /lib64/libc.so.6 (0x0000003ab0000000)
/lib64/ld-linux-x86-64.so.2 (0x0000003aafc00000)

and my libc.so.6 already points to libc-2.5.so

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 07:51 PM.