#!/bin/sh # # A simple shell script to stop Firefox using CPU and paging in RAM # # John C. McCabe-Dansted, 2009 # Permission is given to use this file under any version of the GPL or LGPL. # # Bugs: 1) Only checks if one Firefox window is minimised, others may be # unminimized, but this will still leave Firefox halted and unresponsive # until the window this is actually checking is unminimized # # 2) Do not minimize Firefox while downloading, or the download will # time out. # # 3) This script itself will use a tiny bit of CPU and RAM while polling # xwininfo to determine whether Firefox is minimised. You may want to tune # DELAY. Note that Firefox will be unresponsive for up to DELAY seconds # after being unminimised. DELAY=1 # in seconds main () { WinID=$1 PID=$3 echo WinID: $WinID echo PID: $PID set_running () { if [ "$active" = "yes" ] then kill -s CONT $PID else kill -s STOP $PID fi } set_nice () { if [ "$active" = "yes" ] then renice +0 $PID else renice +19 $PID fi } kill -s CONT $PID running=yes while true do if xwininfo -id $WinID | grep 'Map State: IsUnMapped' > /dev/null then #Minimized active=no else active=yes fi if [ "$active" = no ] then sleep 0.1 kill -s STOP $PID sleep 0.5 if ! kill -s CONT $PID then exit fi else sleep $DELAY fi #echo $active if [ ! "$running" = "$active" ] then set_nice running="$active" fi done } main `wmctrl -l -p | grep " - Mozilla Firefox$"`