Skip to content

Instantly share code, notes, and snippets.

@rad3ks
Created December 19, 2012 22:38
Show Gist options
  • Save rad3ks/4341204 to your computer and use it in GitHub Desktop.
Save rad3ks/4341204 to your computer and use it in GitHub Desktop.
Simple script for Mac users who feel lack of free memory. Script automatically purges memory every 10 minutes, if there is less than 20 MB free.
#! /bin/sh
# Purging memory if there is less than 20 MB free.
# Author: Radosław Szeja
# Date: 9.12.2012
while true; do
fm=`top -l 1 | awk '/PhysMem/ {print $10}' | sed -e 's/\([0-9]*\)\(M\)/\1/g'`;
if [ $fm -lt '20' ];then
`purge`;
free_mem=`top -l 1 | awk '/PhysMem/ {print $10}' | sed -e 's/\([0-9]*\)\(M\)/\1/g'`;
let sum=$free_mem-$fm
echo "${sum}M of memory has been purged.";
fi
sleep 10*60;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment