Quantcast
Channel: The Raspberry Pi Hobbyist
Viewing all articles
Browse latest Browse all 60

Low Memory Automatic Reboot

$
0
0
Below is my solution to the memory leak problem that I discovered in the frame buffer interface used by my digital picture frame.  My first thought was to simply schedule a reboot at midnight, but the Raspberry Pi has no internal clock.  My picture frame is not connected to the network, so it never really knows what time it is. Also, the low memory system hang may occur in less than 24 hours.

The better solution is to monitor the amount of free system memory and reboot when it gets too low.  I use the /proc file system to access the system memory status, the awk command to pull out the value that I need, and a bash script to tie it all together.

lowmemreboot.sh

#!/bin/bash
declare -i fmem
while [ true ]
do
        fmem=` awk '/MemFree/ { print $2 }' /proc/meminfo`
        if [ "$fmem" -lt "10000" ]
        then
                echo FREE MEMORY IS LOW----FORCING REBOOT
                reboot
                exit
        fi
        sleep 60
done


Note that the command that awk runs is surrounded with single quotes.  The entire command is surrounded with back quotes.  This causes the output of the command to be saved in the fmem variable.

This script is run from /etc/rc.local the same way that wait-for-gpio-trigger.sh is run.  When the free system memory drops below 10K, the system will reboot and all is well again for a while.  Now I can just let the picture frame run forever and not worry about it.

I would like to see someone write a real slideshow program that does multiple transition types and supports controls such as pause and reverse.  I have too many more interesting projects on my mind, but maybe someone will find the time to do this.



Viewing all articles
Browse latest Browse all 60

Trending Articles