Skip to content

Instantly share code, notes, and snippets.

@reven
Created February 24, 2017 08:14
Show Gist options
  • Save reven/d27240df6e2b40a038644b127b3d6393 to your computer and use it in GitHub Desktop.
Save reven/d27240df6e2b40a038644b127b3d6393 to your computer and use it in GitHub Desktop.
A script to get memory info in mac os x with only one call to vm_stat
#!/bin/sh
/usr/bin/vm_stat | sed 's/\.//' | awk '
/free/ {FREE_BLOCKS = $3}
/inactive/ {INACTIVE_BLOCKS = $3}
/speculative/ {SPECULATIVE_BLOCKS = $3}
/wired/ {WIRED_BLOCKS = $4}
END {
printf "Free: %s\n", ((FREE_BLOCKS+SPECULATIVE_BLOCKS)*4096/1048576)
printf "Inactive: %s\n", ((INACTIVE_BLOCKS)*4096/1048576)
printf "Total Free: %s\n" ((FREE_BLOCKS+SPECULATIVE_BLOCKS+INACTIVE_BLOCKS)*4096/1048576)
printf "Wired: %s\n", ((WIRED_BLOCKS)*4096/1048576)
printf "Active: %s\n", (4096-((FREE_BLOCKS+SPECULATIVE_BLOCKS+INACTIVE_BLOCKS+WIRED_BLOCKS)*4096/1048576))
printf "Total Used: %s\n", (((INACTIVE_BLOCKS+WIRED_BLOCKS)*4096/1048576)+(4096-((FREE_BLOCKS+SPECULATIVE_BLOCKS+INACTIVE_BLOCKS+WIRED_BLOCKS)*4096/1048576)))
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment