Skip to content

Instantly share code, notes, and snippets.

@rezan
Created March 4, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezan/f73af700370dcd2a72f1 to your computer and use it in GitHub Desktop.
Save rezan/f73af700370dcd2a72f1 to your computer and use it in GitHub Desktop.
Calculate unreferenced memory for a PID
#!/bin/bash
if [ "$1" = "" ]
then
echo "Pass in a PID"
exit 1
fi
SMAPS=/proc/$1/smaps
if [ ! -f $SMAPS ]
then
echo "/proc smaps file not found for PID $1"
exit 1
fi
cat $SMAPS | awk '
$1 == "Size:" {
size += $2;
sunit = $3;
}
$1 == "Referenced:" {
ref += $2;
runit = $3;
}
END {
printf("Total: %12s %s\n", size, sunit);
printf("Referenced: %12s %s\n", ref, runit);
printf("Unreferenced: %12s %s\n", (size - ref), runit);
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment