[wd_asp elements=’search’ ratio=’100%’ id=1]

Detect process running, if not, restart it

25th December 2014

Raspberry-Pi

Raspberrypi - Codehaven

In a bash environment:
If your program was not found in the process list it will be started again. It tests every 2 minutes in this example and the loop runs forever (press ctrl-c to break).

Good to run at start up for a robot program, just turn on and it goes!, any errors and it still should run again after 2 minutes.

#!/bin/bash
while true; do
ps --no-headers -C sudo python robot.py || sudo python robot.py
sleep 2m
done