[EMAIL PROTECTED] writes:
> On Fri, Oct 04, 2002 at 08:24:12PM +0200, Slaven Rezic wrote:
> > Not a module, but a function which should work on FreeBSD and Linux:
>
> Why not package this up and stick it on CPAN? Proc::Memory or
> something.
Because it'a another module to maintain :-) The function is in my
private perl function repository, and I thought about creating a
public function repository on CPAN...
Regards,
Slaven
> It's a good start <nitpick>though you'll probably want
> to do it File::Spec style with Proc::Memory::FreeBSD, etc...</nitpick>
>
>
> > =item currmem([$pid])
> >
> > =for category System
> >
> > Return ($mem, $realmem) of the current process or process $pid, if $pid
> > is given.
> >
> > =cut
> >
> > sub currmem {
> > my $pid = shift || $$;
> > if (open(MAP, "/proc/$pid/map")) { # FreeBSD
> > my $mem = 0;
> > my $realmem = 0;
> > while(<MAP>) {
> > my(@l) = split /\s+/;
> > my $delta = (hex($l[1])-hex($l[0]));
> > $mem += $delta;
> > if ($l[11] ne 'vnode') {
> > $realmem += $delta;
> > }
> > }
> > close MAP;
> > ($mem, $realmem);
> > } elsif (open(MAP, "/proc/$pid/maps")) { # Linux
> > my $mem = 0;
> > my $realmem = 0;
> > while(<MAP>) {
> > my(@l) = split /\s+/;
> > my($start,$end) = split /-/, $l[0];
> > my $delta = (hex($end)-hex($start));
> > $mem += $delta;
> > if (!defined $l[5] || $l[5] eq '') {
> > $realmem += $delta;
> > }
> > }
> > close MAP;
> > ($mem, $realmem);
> > } else {
> > undef;
> > }
> > }
> > __END__
>
> --
> Michael G Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
> Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
>
--
Slaven Rezic - [EMAIL PROTECTED]
BBBike - route planner for cyclists in Berlin
WWW version: http://www.bbbike.de
Perl/Tk version: http://bbbike.sourceforge.net