resource.getrusage() broken under Linux?

Michael Hudson mwh21 at cam.ac.uk
Wed May 3 15:16:51 CEST 2000


Tim Churches <tchur at bigpond.com> writes:

> I checked the FAQs and email archives but couldn't find anything on
> this. Using Python 1.5.2 compiled under SuSE Linux 6.1 (kernel 2.2.7),
> the getrusage() function in the resource library module correctly
> returns the user and system mode time used by the Python process as the
> first two items of its return value, but all the other items, which are
> supposed to indicate memory utilisation, return zero. Is this a known
> problem under Linux? Any work-arounds? 

Well, I can't claim to be knowledgeable about this sort of thing, but
it's hard to see how resource.getrusage could return something
different to getrusage(2), and indeed compiling the following rather
grotesque C

#include <sys/resource.h>

#define SIZE (16*1024*1024)

int main(void)
{
	struct rusage ru;
	char* pMem = malloc(SIZE);
	memset(pMem,0,SIZE);
	getrusage(RUSAGE_SELF,&ru);
	return *((int*)-10);
}

and executing

$ gcc -g ru.c && ./a.out; (echo "print ru" | gdb -q a.out core)

produces:

$1 = {ru_utime = {tv_sec = 0, tv_usec = 30000}, ru_stime = {tv_sec = 1, 
    tv_usec = 160000}, ru_maxrss = 0, ru_ixrss = 0, ru_idrss = 0, 
  ru_isrss = 0, ru_minflt = 4110, ru_majflt = 785, ru_nswap = 0, 
  ru_inblock = 0, ru_oublock = 0, ru_msgsnd = 0, ru_msgrcv = 0, 
  ru_nsignals = 0, ru_nvcsw = 0, ru_nivcsw = 0}

which indeed looks rather like what python says.

Make of this what you will...

Cheers,
M.

-- 
  nonono,  while we're making wild  conjectures about the behavior 
  of completely  irrelevant tasks,  we must not  also make serious 
  mistakes, or the data might suddenly become statistically valid.
                                      -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list