chatchai_j icon

killfirefox

chatchai_j | PRO | 10/03/13 04:30:12 AM UTC | 0 ⭐ | 340 👁️ | Never ⏰ | []
Bash |

550 B

|

None

|

0 👍

/

0 👎

#!/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