Ok, I’ll try this.

For real now.

Yesterday my notebook’s fan had its last spins. The bastard was bugging me for a while but now it’s gone.. was I a bit more emotional I’d probably be crying now.

So basically, my notebook is running on fukushima-mode. No fan.. wild and dangerous computing. The problem is that whenever I get into something serious (any long compilation or watching a 1080p snowboarding video like this) it grows hotter and hotter until the kernel steps in with a VERY mean attitude, killing the whole thing and shutting down the machine and interrupting whatever I was doing.

At some point I figured I could manually kill -STOP $naughtyJob wait for the cpu to cool it’s guts and then let the naughtyjob continue whatever it was doing with -CONT. Nice idea.. I bet you can’t do that on Windows – well, probably you can but I don’t wanna know and don’t come telling me!

The problem is that sometimes you just don’t realise the damn machine is already too hot until you see the shutdown screen and start raving about the new FAN that’s not even on the mail yet! The rational thing a Control Engineer would do is automate the -STOP/-CONT process – behold the life-saving shell script! Wasn’t god written in awk anyway?

The basic idea is to set a “too hot” and a “chilling” points; if it’s too hot the script STOPs the processor using more CPU at the time. If it’s chilling, the script CONTs those processes. You definitely need a quite big band in between the two points (see Hysteresis)  so that your script won’t run amok on you and get everything even worse.. I’m with 65ºC/80ºC now.

Drumroll please… (Ok.. this is just a hour-hack.. works for me, saving the day till my new fan arrives)

#!/bin/bash
hotT=80
coolT=65

watchT=1
coolDownT=3

while true;
do
sleep $watchT
temp=`cat /proc/acpi/thermal_zone/THM/temperature | awk '{print $2}'`

if [ $temp -lt $coolT ]
then
echo "Chilling"
cat haltedReactors.list | while read -e tLine;
do
fukuPid=`echo $tLine | awk '{print $2}'`
fukuComm=`echo $tLine | awk '{print $3}'`
kill -CONT $fukuPid
zenityLine="Restarted "$fukuComm", pid: "$fukuPid
zenity --info --text "$zenityLine"&
done
rm -f haltedReactors.list
touch haltedReactors.list
fi

if [ $temp -gt $hotT ]
then
echo "Burning"

fukushimaLine=`ps -A -o pcpu,pid,comm --sort pcpu | tail -n 1`
fukushimaPid=`echo $fukushimaLine | awk '{print $2}'`
fukushimaComm=`echo $fukushimaLine | awk '{print $3}'`

kill -STOP $fukushimaPid
zenityLine="Stopped "$fukushimaComm", pid: "$fukushimaPid
echo $zenityLine
zenity --info --text "$zenityLine"&

echo $fukushimaLine >> haltedReactors.list
sleep $coolDownT

fi

done

I’m using this for two hours now. So far firefox-bin was paused twice and spotify once. On the bright side, the hot machine’s running strong since this ungodly morning started.

Have fun!