Created
          March 4, 2016 16:01 
        
      - 
      
 - 
        
Save rezan/f73af700370dcd2a72f1 to your computer and use it in GitHub Desktop.  
    Calculate unreferenced memory for a PID
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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