#!/bin/bash
APP="iceweasel" # Process name -- this is firefox on debian
MAXMEM=50 # MAX Memory use in percent
while true; do
sleep 1
LINE=`ps ux | sort -rn -k3 | grep $APP | head -1`
if [ "$LINE" ]; then
MEM=`echo $LINE | awk '{ print $4; }' | cut -f1 -d.`
PROCID=`echo $LINE | awk '{ print $2; }'`
if [ "$MEM" -gt "$MAXMEM" ]; then
echo "Going to kill $PROCID"
## uncomment the following line to actually kill the process
# kill -9 $PROCID
fi
fi
done
Comments