$ ./size-check SIZE: 3792.000 SHARED: 324.000 UNSHARED: 3468.000 LENGTH($x): 0 $ ./size-check Allocating a large string SIZE: 23332.000 SHARED: 444.000 UNSHARED: 22888.000 LENGTH($x): 10000000 $ #### #!/usr/bin/perl our $x; if (rand(10) < 5) { print "Allocating a large string\n"; $x = ' ' x 10_000_000; } my $pid = fork(); die "unable to fork: $!" unless defined($pid); if ($pid) { # parent wait; } else { report_size(); } sub report_size{ my ($total, $shared) = _linux_size_check(); my $unshared = $total - $shared; printf "SIZE: %.3f SHARED: %.3f UNSHARED: %.3f LENGTH(\$x): %d\n", $total, $shared, $unshared, length($x); } # borrowed rom Apache::SizeLimit sub _linux_size_check { my ( $size, $share ) = ( 0, 0 ); if ( open my $fh, '<', '/proc/self/statm' ) { ( $size, $share ) = ( split /\s/, scalar <$fh> )[0,2]; close $fh; } else { die "Fatal Error: couldn't access /proc/self/status"; } # linux on intel x86 has 4KB page size... return ( $size * 4, $share * 4 ); }