|
Boost Users : |
From: Sachin Garg (schngrg_at_[hidden])
Date: 2008-07-29 13:38:04
On Tue, Jul 29, 2008 at 9:25 PM, Bob Wilkinson
<rwilkinson_at_[hidden]> wrote:
> On Tue, Jul 29, 2008 at 02:53:01PM +0530, Sachin Garg wrote:
>> When using semaphores to synchronize separate processes, everything
>> works fine when each process exits nicely (closing its semaphores
>> before exit). But things get really messy when a process might crash.
>> I am unable to figure out how to recover from such a crash which
>> leaves semaphores in inconsistent state.
>>
>> If a semaphore is not in-use (open) by any process, in this case (in
>> my application) I can safely 'remove' it and start afresh. Is there
>> some way to find out if any process is using a semaphore at a time so
>> that I can call 'remove'?
>>
>> When I just add a 'remove' on process start this works great on
>> windows (as remove just fails if another process has the semaphore
>> open), but on linux sem_unlink is used which has the behavior of
>> deleting it even if its in use.
>>
>> What is the general practice when it comes to cleaning up semaphores
>> after process crashes? Maybe some way to ensure that 'post' and
>> 'close' are always called even when application has otherwise crashed?
>> Is there some way to use boost's windows style semaphores on linux
>> instead of native posix style?
>>
>> I tried looking and many have asked this question (in context of
>> recovering from posix semaphores, which are used by boost on linux),
>> but I couldn't find any answers. Lars had asked this here also, almost
>> an year ago but no answers in that thread either. This seems like a
>> basic issue but am totally lost on how to even approach it.
>
> ipcs -s -p will show a list of semaphores and the
> associated pids of the process which created them.
>
> Using the pids obtained from the above, you can check the
> process table to check whether the process is still alive?
>
> e.g.
> (N.B. I use the -m, rather than the -s option to ipcs for
> illustration, since I have no semaphores, but do have
> shared memory used).
>
> bob_at_spain:~$ ipcs -m -p
[snip]
>
> A little perl script could be written to do this.
I have a named semaphore so can I do all this only for that one named
semaphore? And can this be done programatically without relying on
external executables?
If its possible (I hope it is), will it make sense to add such a
smart_remove to boost interprocess? Idea behind using boost was to
make my code portable and hide the platform related intricacies. Doing
all this myself squarely defeats that purpose (but for now, I would
still love to know the solution if any :-).
Thanks,
Sachin Garg
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net