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

后端 未结 8 569
轻奢々
轻奢々 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:36

    You'll need to double check but I believe sem_post can be called from a signal handler. If you are able to catch some of the situations that are bringing down the process this might help.

    Unlike a mutex any process or thread (with permissions) can post to the semaphore. You can write a simple utility to reset it. Presumably you know when your system has deadlocked. You can bring it down and run the utility program.

    Also the semaphone is usually listed under /dev/shm and you can remove it.

    SysV semaphores are more accommodating for this scenario. You can specify SEM_UNDO, in which the system will back out changes to the semaphore made by a process if it dies. They also have the ability to tell you the last process id to alter the semaphore.

提交回复
热议问题