Program Memoryj Usage from 'C'

David Dymm dymm at b.cs.wvu.wvnet.edu
Thu Dec 14 00:44:06 AEST 1989


I want to know exactly (or close to it) how much memory has been
allocated by a 'C' program.  Thus, I want to make a call from athe running
program to determine how much memory the program has currently allocated
on the stack.

I tried using "ps".  Thus I used

   sprintf (buffer, "ps -auxw | grep %d | grep -v grep > outfile", pid_number);
   system (buffer);

where "pid_nubmer" is the pid number of the process.
I then pulled out the string from "outfile" and parsed it to the correct
field ("sz") to get the memory allocated on the stack and data segment.

But this does NOT give consistent results and in fact sometimes gives
very odd results.  Such as telling me that a program has allocated only
8 kb when I know it has allcoated over 30kb.
Is there a better way??  Is there a direct 'C' cal that I can make
to unix to give me the memory allocated on the stack??

David Dymm			Software Engineer

USMAIL: Bell Atlantic Knowledge Systems,
        145 Fayette Street, Morgantown, WV 26505
PHONE:	304 291-2651 (8:30-4:30 EST)
USENET:  {allegra,bellcore, cadre,idis,psuvax1}!pitt!wvucsb!dymm
INTERNET: dymm at b.cs.wvu.wvnet.edu



More information about the Comp.unix.wizards mailing list