How do I recover a semaphore when the process that decremented it to zero crashes?

后端 未结 8 554
轻奢々
轻奢々 2020-12-02 13:23

I have multiple apps compiled with g++, running in Ubuntu. I\'m using named semaphores to co-ordinate between different processes.

All works fine except in

8条回答
  •  [愿得一人]
    2020-12-02 13:43

    If the process was KILLed then there won't be any direct way to determine that it has gone away.

    You could operate some kind of periodic integrity check across all the semaphores you have - use semctl (cmd=GETPID) to find the PID for the last process that touched each semaphore in the state you describe, then check whether that process is still around. If not, perform clean up.

提交回复
热议问题