Advertisement
chatchai_j

killfirefox

Oct 2nd, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.55 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. APP="iceweasel"     # Process name -- this is firefox on debian
  4. MAXMEM=50           # MAX Memory use in percent
  5.  
  6. while true; do
  7.     sleep 1
  8.     LINE=`ps ux | sort -rn -k3 | grep $APP | head -1`
  9.     if [ "$LINE" ]; then
  10.         MEM=`echo $LINE | awk '{ print $4; }' | cut -f1 -d.`
  11.         PROCID=`echo $LINE | awk '{ print $2; }'`
  12.         if [ "$MEM" -gt "$MAXMEM" ]; then
  13.             echo "Going to kill $PROCID"
  14.         ## uncomment the following line to actually kill the process
  15.             # kill -9 $PROCID
  16.         fi
  17.     fi
  18. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement