LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-22-2009, 06:39 AM   #1
faristol
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)?


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
 
Old 04-23-2009, 12:53 PM   #2
rriggs
Member
 
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
faristol
LQ Newbie
 
Registered: Apr 2009
Location: Barcelona
Distribution: Red Hat Enterprise Linux 5.3
Posts: 4

Original Poster
Rep: Reputation: 0
Question

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?
 
  


Reply

Tags
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


All times are GMT -5. The time now is 02:13 AM.

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