use strict; print join("\n", &usage("jvm")), "\n"; # this subroutine takes only one parameter, the process name # to return memory usage information on # # Returns array of two values, raw process memory size and # percentage memory utilisation, in this order. Returns # undefined if these values cannot be determined. sub usage { use Proc::ProcessTable; my @usage; my $proc = Proc::ProcessTable->new; my %fields = map { $_ => 1 } $proc->fields; return undef unless exists $fields{'cmnd'}; foreach (@{$proc->table}) { if ($_->cmnd =~ /$_[0]/) { my @proc; push (@proc, $_->size) if exists $fields{'size'}; push (@proc, $_->pctmem) if exists $fields{'pctmem'}; push @usage, \@proc; } } return @usage; }