steves has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to get the size of a process from Perl? Preferably in a portable way, or at least portable across Unix variants.

Replies are listed 'Best First'.
Re: Getting Process Size
by edan (Curate) on Sep 12, 2004 at 15:04 UTC

      Proc::ProcessTable

      That was my original idea, as well -- until I checked the relevant README files and found that there are some platforms for which process size reporting isn't available. And for some of the covered operating systems, the procfs functionality which Proc::ProcessTable requires is strongly deprecated (e.g. FreeBSD).

Re: Getting Process Size
by steves (Curate) on Sep 12, 2004 at 15:14 UTC

    Not sure how I missed that. Thanks! At least we have a search entry for in on PerlMonks now. ;-)

Re: Getting Process Size
by zentara (Cardinal) on Sep 13, 2004 at 14:10 UTC
    Yeah, Proc::ProcessTable is a big wasteful module, since it makes you load all process data to work with it. If you are on Linux, you can go directly to /proc and get your information. For example:
    #!/usr/bin/perl use warnings; use strict; my $pid = shift || $$; print get_size($pid),"\n"; sub get_size{ my $pid = shift; my @size = split "\n", `cat /proc/$pid/status`; (my $vmsize) = grep {/VmSize/} @size; my (undef,$size) = split ' ',$vmsize; return($size); }

    I'm not really a human, but I play one on earth. flash japh