Where is my memory usage? (getrusage)

Soren Ragsdale soren at pobox.com
Thu Sep 20 21:57:09 EDT 2001


Let's assume I have a program (eat.py) which uses some memory:

==============================================================
i = 1
while 1:
    j = range(i)
    i = i * 2
    if i > 1024*1024*4:
        break
==============================================================

and I have a program which executes this program (size.py)

==============================================================
import os,resource,sys
os.system("python eat.py")
print sys.platform
print " Self",resource.getrusage(resource.RUSAGE_SELF)
print "Child",resource.getrusage(resource.RUSAGE_CHILDREN)
==============================================================
linux-i386
Self (0.01, 0.01, 0, 0, 0, 0, 115, 293, 0, 0, 0, 0, 0, 0, 0, 0)
Child (1.88, 0.55, 0, 0, 0, 0, 34597, 507, 0, 0, 0, 0, 0, 0, 0, 0)
==============================================================
irix646
Self (0.04718, 0.047292, 320, 0, 0, 0, 182, 6, 0, 17, 0, 0, 0, 0, 61,
103)
Child (3.722367, 0.582003, 102784, 0, 0, 0, 208, 0, 0, 1, 0, 0, 0, 0,
43, 0)
==============================================================

Why doesn't getrusage report the memory usage of my child process?  It
looks like this bug only appears under linux in both 2.2 and 2.4
kernels.  To refresh your memory:

Offset   Resource 
0        time in user mode (float)
1        time in system mode (float)
2        maximum resident set size
3        shared memory size
4        unshared memory size
5        unshared stack size



More information about the Python-list mailing list