best way to discover this process's current memory usage, cross-platform?

sjdevnull at yahoo.com sjdevnull at yahoo.com
Wed Nov 16 19:34:10 CET 2005


Neal  Norwitz wrote:
> Here's a really screwy thought that I think should be portable to all
> Unixes which have dynamic linking.  LD_PRELOAD.
>
> You can create your own version of malloc (and friends) and free.  You
> intercept each call to malloc and free (by making use of LD_PRELOAD),
> keep track of the info (pointers and size) and pass the call along to
> the real malloc/free.  You then have all information you should need.

That'll only get you memory usage from malloc/free calls, which could
be vastly less than the process' memory usage in plausible scenarios
(e.g. a media player that uses mmap() to read the file, or anything
that uses large shared memory segments generated with mmap() or SysV
IPC, etc).

In the real world, malloc() and mmap() are probably sufficient to get a
good picture of process usage for most processes.  But I guess defining
exactly what counts as the process' current memory would be a starting
place (specifically how to deal with shared memory).




More information about the Python-list mailing list