We have a mission-critical server program on top of Linux and we don\'t want others to terminate it accidentally. If somebody terminates it or it crashes, we want it to rest
They would have to poll each other, typically. Have them send signal zero to each other (which just checks for aliveness and does not interrupt the other program).
echo $$>$1
read otherpid < $2
while :; do
while kill -0 $otherpid
do
sleep 1
done
# restart other program
# (really restarting myself in my peer configuration)
$0 $2 $1 &
newpid=0
while [ "$newpid" -eq "$otherpid" ]
do
sleep 2
read newpid < $2
done
otherpid=$newpid
done
You could go more fancy and try to do watchdog stuff to make sure that the program is not only existing, but actually running.