LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   System call to get current process memory usage? (http://www.linuxquestions.org/questions/programming-9/system-call-to-get-current-process-memory-usage-425190/)

mattengland 03-15-2006 06:25 PM

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

ckoniecny 03-15-2006 06:50 PM

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.

mattengland 03-15-2006 06:53 PM

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

primo 03-15-2006 06:56 PM

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).

ckoniecny 03-15-2006 07:07 PM

I'm sorry, I misunderstood your question.


All times are GMT -5. The time now is 01:40 PM.