Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-22-2009, 06:39 AM   #1
LQ Newbie
Registered: Apr 2009
Location: Barcelona
Distribution: Red Hat Enterprise Linux 5.3
Posts: 4

Rep: Reputation: 0
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?


Old 04-23-2009, 12:53 PM   #2
Registered: Mar 2009
Location: Colorado, US
Distribution: Fedora 13, Fedora 14, RHEL6 Beta
Posts: 46

Rep: Reputation: 17
Check the getrusage(2) manpage but note the caveats.

Last edited by rriggs; 04-23-2009 at 12:56 PM.
Old 04-24-2009, 08:41 AM   #3
LQ Newbie
Registered: Apr 2009
Location: Barcelona
Distribution: Red Hat Enterprise Linux 5.3
Posts: 4

Original Poster
Rep: Reputation: 0

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?


c++, linux, memory

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to show the memory usage per process ty263 Linux - General 3 09-12-2008 06:36 AM
Does process memory usage drop? Zeno McDohl Linux - Newbie 3 07-10-2008 11:40 PM
how to find max memory usage for process in Linux by command line kashameni Linux - Newbie 9 06-01-2007 01:39 AM
getrusage and process memory usage gearoid_murphy Programming 2 11-09-2006 04:33 AM
Process memory usage wombat53 Linux - Newbie 5 07-21-2005 07:42 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration