User avatar
dbasberg
Posts: 56
Joined: Fri Jul 13, 2012 7:28 pm
Location: Michigan, USA

Check for crashed program periodically?

Sun Nov 18, 2018 7:46 pm

I use one of my PIs to control a solar power system. It needs to be running always. The Modbus connection is run with a less than perfect library routine. It can crash periodically. I would like to test periodically for the program executing and restart it if not executing. Perhaps I can use 'crontab' to do this. I am not very Linux or shell competent and wonder how I can test for my program executing periodically and then restarting if necessary. Any help with this is greatly appreciated. This is key to my handling of critical programs. :?:
Five RPIs: 2:256 & 2:512 and an RPI3 used for monitor and control in out buildings of farm (embedded controls). Linux/Python novice. Experienced real-time programmer/hardware/systems designer (asm, C, C++).

Andyroo
Posts: 3850
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Check for crashed program periodically?

Sun Nov 18, 2018 8:36 pm

Not sure if I would get cause more outrage for saying fix your program or do not use the Pi for mission critical devices so i’ll avoid them like the plague :mrgreen: and say for you to have a look at watchdog timers..

This series of articles https://www.switchdoc.com/2017/08/relia ... -arduinos/ is a good coverage of this process as a place to start.
Need Pi spray - these things are breeding in my house...

User avatar
rpdom
Posts: 14785
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Check for crashed program periodically?

Sun Nov 18, 2018 9:07 pm

It might be worth a look at the supervisor package. It's a program that will start other programs for you and restart them if they fail. I think it's written in Python.

rzusman
Posts: 346
Joined: Fri Jan 01, 2016 10:27 pm

Re: Check for crashed program periodically?

Sun Nov 18, 2018 9:34 pm

You can create a system service that will re-launch a crashed process automatically.

https://medium.com/@benmorel/creating-a ... 1b5c8b91d6

This won’t fix a hung process - you need a watchdog for that.

User avatar
dbasberg
Posts: 56
Joined: Fri Jul 13, 2012 7:28 pm
Location: Michigan, USA

Re: Check for crashed program periodically?

Mon Nov 19, 2018 1:36 am

The library I use for serial modbus is not mine. I do not see where to fix it.
The advise you three have given me has set me to learning. I think my answer is in there somewhere.
Thanks for the help.
It is up to me to learn now. :D
Five RPIs: 2:256 & 2:512 and an RPI3 used for monitor and control in out buildings of farm (embedded controls). Linux/Python novice. Experienced real-time programmer/hardware/systems designer (asm, C, C++).

User avatar
dbasberg
Posts: 56
Joined: Fri Jul 13, 2012 7:28 pm
Location: Michigan, USA

Re: Check for crashed program periodically?

Mon Nov 19, 2018 5:47 pm

rzusman wrote:
Sun Nov 18, 2018 9:34 pm
You can create a system service that will re-launch a crashed process automatically.

https://medium.com/@benmorel/creating-a ... 1b5c8b91d6

This won’t fix a hung process - you need a watchdog for that.
I am exploring this for more than this current problem. It looks like a powerful approach for other things I do regularly. My thanks to you for taking the time to point me in this direction. 8-)
Five RPIs: 2:256 & 2:512 and an RPI3 used for monitor and control in out buildings of farm (embedded controls). Linux/Python novice. Experienced real-time programmer/hardware/systems designer (asm, C, C++).

Return to “Advanced users”