0

I'm developing a robot using python on raspberry pi. This robot has DC motors and can move. The movement of robot is controlled by main program. If by any reason main program crash, robot keep going and may make some damages. I want to know if there is any way to watch main program and check if it is alive or not, if it's not, watcher program stop motors. Please help me, thank you all.

  • how/why is your main program crashing? Is it throwing an exception? – 101donutman May 05 '21 at 18:30
  • Instead of running main program directly, you could have a program whose only job is to run main and wait for SIGCHLD. This program would then do the cleanup. – tdelaney May 05 '21 at 18:32
  • on LInux for web pages people use [supervisord](http://supervisord.org/) to control if it still running and restart it when it crushed. But it may not be useful for you. Some programs at start save `Process ID` in file (often in `/var/your_program.lock`) and they delete this file at the end - they can use it to check if previous instance is still running. Or to kill previous instance. But you can create other program which get this Process ID to check in system if it still running. – furas May 05 '21 at 20:36
  • [Check if a process is running or not on Windows with Python](https://stackoverflow.com/questions/7787120/check-if-a-process-is-running-or-not-on-windows-with-python) - OP asks for Windows but answer uses `psutil` which works also on Linux. – furas May 05 '21 at 20:42

0 Answers0