Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Find memory usage of perl program

by toma (Vicar)
on Feb 16, 2003 at 18:06 UTC ( #235757=snippet: print w/ replies, xml ) Need Help??

Description: Proc::ProcessTable has access to the sort of information found in programs like top and ps. This sub finds the memory usage of the program that calls it.

Proc::ProcessTable currently works on windows, linux, solaris, aix, hpux, freebsd, irix, dec_osf, bsdi, netbsd, unixware 7.x and SunOS.

The windows port requires the Cygwin environment.

use Proc::ProcessTable;
print "My memory=", memory_usage(), "\n";

sub memory_usage {
  my $t = new Proc::ProcessTable;
  foreach my $got ( @{$t->table} ) {
    next if not $got->pid eq $$;
    return $got->size;
  }
}
Comment on Find memory usage of perl program
Download Code
Re: Find memory usage of perl program
by Anonymous Monk on May 06, 2008 at 19:59 UTC

    i just made a simple script to test this out and..

    #!/usr/bin/perl use Proc::ProcessTable; sub memory_usage { my $t = new Proc::ProcessTable; foreach my $got ( @{$t->table} ) { next if not $got->pid eq $$; return $got->size; } } print 'memory: '. memory_usage()/1024/1024 ."\n";

    Running it results in:

    $ ./test.pl memory: 6.26953125

    how normal is that?

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://235757]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-12-28 17:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls