resource module returns just zeros

Cameron Simpson cs at zip.com.au
Mon Oct 4 18:49:40 EDT 2010


On 04Oct2010 09:02, Adam Tauno Williams <awilliam at whitemice.org> wrote:
| I'm using a call to the resource module's getrusage method.  On openSUSE
| this works, on CentOS [python26-2.6.5-3.el5] it 'works' but just returns
| zeros for the memory utilization values.
| 
| resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
| 
| openSUSE: returns 5512
| CentOS:   returns 0
| 
| Anyone know what condition causes this?  Or is there a better /
| more-reliable way to check memory utilization of the current process?

Long standing Linux shortcoming. "man getrusage" on a handy Gentoo box
says:

  The structure definition shown at the start of this page was taken from
  4.3BSD Reno.  Not all fields are meaningful under Linux.  In Linux  2.4
  only  the fields ru_utime, ru_stime, ru_minflt, and ru_majflt are
  maintained.  Since Linux 2.6, ru_nvcsw and ru_nivcsw are  also maintained. 
  Since Linux 2.6.22, ru_inblock and ru_oublock are also maintained.

I ran across this deficiency a few years back hoping to get some memory
stats for some software engineeers in a former life.

I suggest you compare the kernel versions on your systems; CentOS tracks
RedHat, which keeps moderately old kernel revisions (because the kernel
revision stays stable over a given release - such stability is one of
the things you get with such a distro).

There's the ps command, antoher amazingly differing command across
platforms (though usually compatible on a given tool distro - your Linux
boxen will has GNU ps).

Also look in /proc - the info may be available there - I expect that's
where a Linux ps gets a lot of info.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

I do not like this word 'bomb'. It is not a bomb.  It is a device which
is exploding.   - Jacques Le Blanc, French Ambassador to New Zealand,
                  on the tests of nuclear "exploding devices"
                  in French Polynesia.



More information about the Python-list mailing list