LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   getrusage and process memory usage (https://www.linuxquestions.org/questions/programming-9/getrusage-and-process-memory-usage-499775/)

gearoid_murphy 11-08-2006 11:24 AM

getrusage and process memory usage
 
hello,
I'm using getrusage to tell me how much stack space I'm using as I go through a series of recursive calls. Heres the code :

struct rusage usage ;
if(getrusage(RUSAGE_CHILDREN, &usage) != 0)
{
cout<<"getrusage failed"<<endl ;
exit(0);
}

cout<<"Shared Memory = "<<usage.ru_ixrss<<endl ;
cout<<"Unshared Data Size = "<<usage.ru_idrss<<endl ;
cout<<"Unshared Stack Size = "<<usage.ru_isrss<<endl ;

However each of the outputs only produces a zero. The program I'm running will use well over 2 gigs of ram (sometimes more...argh!). I'm trying to eliminate superfluous variables by this kind if analysis.

Can anyone tell me why getrusage isn't detecting the stack space I'm using and / or alternative methods of extracting the info I'm looking for.

Cheers,
Gearoid

paulsm4 11-08-2006 01:11 PM

man getrusage:
Quote:

The above struct was taken from BSD 4.3 Reno. Not all fields are meaningful under Linux. Right now (Linux 2.4, 2.6) only the fields ru_utime, ru_stime, ru_minflt, ru_majflt, and ru_nswap are maintained.
PS:
Perhaps you can try looking in the proc virtual directory, under /proc/<PID>/status:

http://redhat.activeventure.com/9/re...rectories.html

gearoid_murphy 11-09-2006 04:33 AM

many thanks.


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