The following shell script uses the videocore utility vcgencmd measure_temp
to get a line like temp=37.4'C
. It then does some string magic to isolate the 37
from that string, which is then compared to 35. If it's greater, $HOT_PID is killed. That PID was set to the program in question, which was started in the background.
#!/bin/sh
/path/to/hot/app &
HOT_PID=$!
[ $(vcgencmd measure_temp|{ IFS== read DUMMY TEMP ; echo $TEMP ; }|{ IFS=. read INTTEMP DUMMY ; echo $INTTEMP ; }) -gt 35 ] && kill $HOT_PID
Note this fails on applications which fork, because you had to kill all the child processes, too. But you could still use the test line as a base and make a better script. Or simply shutdown now
the Pi.