how to protect my process from being killed?

后端 未结 4 2042
故里飘歌
故里飘歌 2021-01-01 00:32

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

4条回答
  •  迷失自我
    2021-01-01 00:50

    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.

提交回复
热议问题