Reputation: 516
Is it possible to emulate the System V primitive semctl(semid,0,GETPID,0)
in an environment using POSIX semaphores?
If it is not possible, I'm looking for a method to know who has done the last operation on a semaphore, I'm going to explain better...
I'm developing a UDP server with preforked children. The father handles SIGCHLD to respawn a dead child. If a child dies in the critical section (namely it has not yet done the sem_post) the father has to recognize this situation and unlock the semaphore.
Upvotes: 1
Views: 601
Reputation: 215627
What you want cannot be done. You could emulate the behavior partly by writing your own semaphore based on POSIX robust mutexes (but it would have some disadvantages like not being async-signal-safe), or you could just use a robust mutex instead of a semaphore to begin with.
Upvotes: 0
Reputation: 182784
I don't think it can be done. I don't see anything like this mentioned in the standard. Your best bet would be to ensure the application has no reason to die in a critical section.
You might think of attaching some state information to each semaphore ("who did the last DOWN on this semaphore?"). But then, if multiple processes are allowed to do a down on the semaphore (the semaphore starts with a value greater than 1) you will have to synchronize the way they are updating that information - back to square 1.
Upvotes: 1