I have a unstable program that kept crashing randomly, I could use a bash script to keep it running, but is there a way to monitor it’s state ? Not by polling, but event-driven.
And and optional question, what if the monitor process isn’t the parent process of it, is this still possible ?
You can write a simple wrapper which forks and execs the crashing process, and just wakes up when it gets SIGCHLD and starts all over again; conceptual code below:
You don’t need anything fancy, just a basic knowledge of how child and parent processes interact via signals.
Please also consider that it’s been a while since I’ve dealt with signal stuff directly, so double-check that the code there is correct.