LinuxQuestions.org
Review your favorite Linux distribution.
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 03-15-2006, 06:25 PM   #1
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Rep: Reputation: 15
System call to get current process memory usage?


What if any system calls exist to get the current process' system memory usage (including all of the current process' threads) in a C/C++ based program?

I'm trying to write unit tests to make sure that my memory allocation processes (for Boost "smart pointers") are actually deallocating correctly after thousands of dynamic allocations...and my presumption is that a process-memory "self check" thoughout this process will be very useful for my self-running unit test.

I'd prefer cross-platform calls (be it POSIX, unix/linux, Boost C++, etc) if I can get them, but I'll take a system specific all (for my testing prototype) if I must.

Thanks for any help,
-Matt

Last edited by mattengland; 03-15-2006 at 06:45 PM.
 
Old 03-15-2006, 06:50 PM   #2
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
Well you can execute the following two commands:

Code:
$ ps -aux
or

Code:
$ top
You can sort top by using Shift-m to sort by memory utilization.
 
Old 03-15-2006, 06:53 PM   #3
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
They need to be system calls *inside* my C/C++ program about my current process. Unfortunately, ps(1) or top(1) will not work, but I appreciate the feedback. Further, a shell call from the code is highly undesirable, and probably will not work at all. Please consider this more of a "real-time" kind of unit test program.

-Matt
 
Old 03-15-2006, 06:56 PM   #4
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Ideally, getrusage() should, but not all fields are supported in Linux, so you must use the /proc/<pid> information which is what ps(1) does. See proc(5).
 
Old 03-15-2006, 07:07 PM   #5
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
I'm sorry, I misunderstood your question.
 
  


Reply


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 programmatically monitor a process memory usage? thanhvn Programming 14 02-20-2009 01:15 AM
how to show the memory usage per process ty263 Linux - General 3 09-12-2008 06:36 AM
how to programmatically monitor a process memory usage? thanhvn Linux - Software 1 11-15-2005 08:44 PM
about displaying process memory usage maginotjr Slackware 2 09-13-2005 11:43 AM
Process memory usage wombat53 Linux - Newbie 5 07-21-2005 07:42 PM


All times are GMT -5. The time now is 10:52 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