Skip to content

Instantly share code, notes, and snippets.

@dnmfarrell
Created February 11, 2022 20:19
Show Gist options
  • Save dnmfarrell/33284a671d6d62dc134d9293d12c4a29 to your computer and use it in GitHub Desktop.
Save dnmfarrell/33284a671d6d62dc134d9293d12c4a29 to your computer and use it in GitHub Desktop.
Use /proc/smaps to show the difference between resident and proportional set size memory
#!/usr/bin/env perl
use strict;
use warnings;
use Linux::Smaps;
sub print_memusage {
my $smaps = Linux::Smaps->new;
printf "% 6s % 9d % 9d KB % 9d KB\n", $_[0], $$, $smaps->rss, $smaps->pss;
}
my @bigarray = (1..1_000_000);
print " LABEL PID RSS PSS\n";
my $pid = fork;
die "failed to fork $!" unless defined $pid;
if ($pid == 0) {
print_memusage("CHILD");
exit;
}
print_memusage("PARENT");
waitpid $pid, 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment