#!/usr/bin/perl -w use strict; use File::Glob ':glob'; my $procregex = qr /^(\S+)-(\S+) \S+ \S+ \S+ (\S+)/; sub process_mapsfile { my ($path) = @_; open(MAPSFD, $path); my $totalsize = 0; while() { if (!/$procregex/) { #print "Couldn't match\n$_\n"; next; } else { #print "Matched\n$_\n"; } #print "line = $_"; my $start = int(hex($1)); my $end = int(hex($2)); my $inode = int($3); #print "inode = $inode, end = $end, start = $start\n"; if($inode == 0) { my $size = $end - $start; $totalsize += $size; } } close(MAPSFD); return $totalsize; } my $totalsize = 0; my @files = ; foreach my $file (@files) { # if we have a pid file, parse maps file if($file =~ /\/proc\/\d+/) { $totalsize += process_mapsfile($file . "/maps"); } } print "size = $totalsize\n";