Raspberry Pi on a hot day


Whatever is causing my Pi to crash corresponds with a spike in heat, but I now suspect it’s not caused by the heat, but rather the heat is generated by whatever is crashing it. The pi is meant to deal with heat problems on it’s own. I’m leaving this up because parts of it are interesting, like suspending processes, writing functions, etc

A specific case

Let’s say you want to build the latest version of inkscape on your raspberry pi computer. And let’s say you want to install it via dpkg. You may find it crashes from overheating.

Fortunately, I’ve got a script for you.

Before running the script, do the following:

  • sudo nano /etc/apt/sources.list
    • Uncomment the line with deb-src in it
  • sudo apt-get update && sudo nice apt-get upgrade -y
  • sudo apt-get build-dep inkscape -y
  • sudo apt-get install build-essential dpkg-dev fakeroot cmake bzr dh-make -y
  • sudo apt-get remove inkscape
  • sudo apt-get autoremove

Then, when it’s done:

./pi_build_inkscape.sh && cd ~Downloads/ && sudo dpkg -i inkscape*.deb

The General Principle

What you need for any overheating for of problem is the ability to check the temperature and then pause processes until it falls. First, how do we check the temperature? Bash functions can’t return values, so we’ll write a global variable.



function get_temp {

echo "$deg c"

That’s good. We can do some testing with $deg and put a process to sleep and wake it up again. But we also need to do subprocesses! We’ll do some recursion.

function pause_proc {
  #renice -n 15 $1
  kill -TSTP  $1
  for i in `ps -ef| awk '$3 == '$1' { print $2 }'`
    #echo "pausing $i"
    pause_proc $i

function resume_proc {
  kill -CONT $1
  for i in `ps -ef| awk '$3 == '$1' { print $2 }'`
    #echo "restarting $i"
    resume_proc $i

Now we just need some way to track if a process is still running, and to sleep between temperature checks etc etc

function run_proc {

  echo "$deg c " `date +%X`

  while kill -0 "$1"; do #run this loop while the process is running


    if [ $deg -ge 49 ] ; then # high temperature is 49
      echo "too hot! $deg c " `date +%X`

      pause_proc $1 # Do this every time in case we missed some last time
      if [ $sleep -eq 5 ] ; then
      elif [ $sleep -eq 10 ] ; then
      elif [ $sleep -lt 5 ] ; then
    if [ $stopped -eq 1 ] ;then
      if [ $deg -le 47 ] #Ok temperature is 47
        echo "cool enough $deg c " `date +%X`
        resume_proc $1

    sleep $sleep


I picked the temperatures of 47 and 49 based on when my pi tends to crash. theoretically, it should be ok up through the 60’s. If you don’t know what’s going on with your pi getting too warm, you can also set a loop in another window to print out the temperature in a loop.

So if we want to use this for some intense process in a script, we could put those functions at the top (under the #!/bin/bash ), and run our command like:

nice -n 15 some_command arg1 arg2 &
run_proc $!

Or if you want to make this a script you can run from the command line with your intense command:

nice -n 15  $@ &
run_proc $!

To add extra resilience to my poor pi, I’ve also put a heat sink on the CPU and, right now, it’s sat in a dry bowl which is sat in another bowl which is full of ice. It’s like one of those old Supercomputers, except probably faster.

Published by

Charles Céleste Hutchins

Supercolliding since 2003

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.