0

I have a Raspberry Pi 3 and I'm thinking of running a process 7/24, but it sometimes uses CPU too much, and from my last 2 questions, I understood that Raspberry Pi 3 cannot power itself off on high temperature. Because of this, I decided to configure raspberry pi to kill that application on high temperature, but I don't have any ideas about how I can do that. How can I do that?

1

1 Answer 1

5

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 smaller, it waits a second, then tests the temperature again. If it's 35 or more, $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=$!
while [ $(vcgencmd measure_temp|{ IFS== read DUMMY TEMP ; echo $TEMP ; }|{ IFS=. read INTTEMP DUMMY ; echo $INTTEMP ; }) -lt 35 ] ; do sleep 1 ; done
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.

3
  • Thanks for the answer. I can't test it now but I'll comment when I test it. Also, isn't 35 too low?
    – user81004
    Commented Feb 25, 2018 at 17:00
  • 1
    Please adjust it as you need it.
    – Janka
    Commented Feb 25, 2018 at 17:00
  • instead of kill it could be useful to suspend process execution with SIGSTOP signal for later resumption
    – Fabian
    Commented Feb 25, 2018 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.