0

I used boost's named_semaphore for IPC. We have one program/process (parent) invoking another (child). If the parent is killed (kill -9 scenario), we want the child to complete its work and exit, and the parent shall, upon starting wait until the child signals (by means of boost::named_semaphore).

This all works quite well, except that the other day on windows I got quite a surprise when I cleared the event log (it happens...) to find out the boost (to obtain kernel persistence shared memory) uses shared memory, and the folder which they use for this uses for its name a timestamp that it obtains (by default) from the event log (in the case of windows only).

Granted, I have not read their IPC documentation entirely (perhaps I believe to firmly in encapsulation...), and I especially did not realize named_semaphore's dependency on shared_memory... (encapsulation).

This / the default behavior of using the Startup Time in the event log from here is too fragile for my liking. They do give some options, but I'm not sure which is the most robust, whilst requiring the least amount of work from my part. Specifically, what degree of robustness has defining BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME and why is this not the default?

I'm assuming that if I use a strategy, both parent and child processes must use exactly the same strategy, otherwise the named_sema won't work?

Any thoughts would be welcome.

Werner Erasmus
  • 3,988
  • 17
  • 31
  • Do you really need the semaphore? Aren't the native process primitives enough? – user207421 Mar 17 '16 at 11:49
  • A named semaphore has often in the past been used for this purpose. The child simply signals to indicate it has exited cleanly, and the parent waits for x amount of seconds if the semaphore can be opened. What other suggestions do you have. The application must be cross platform, running on mac, windows and other nixes. What other suggestions do you have, besides using java? – Werner Erasmus Mar 17 '16 at 12:10
  • Err, using cross-platform process primitives? Posix `wait()`, for example? If Java is an option for you by all means use it, but I haven't said anything about it so I don't know why you mention it. – user207421 Mar 19 '16 at 04:27
  • @EJP, I cannot use wait, as on nixes (I stand corrected) the pid of processed could be recycled. The use case where the parent process dies with kill-9 or end task (windows) and the child is orphaned (temporarily in our case) requires the parent to know when the child has completed its work. For this you can't use wait, as you not be sure that the orphaned child (if pid is persisted) is in actual fact the same child. Yes, one does use wait for a process, but only if you know its pid (in other words, you've typically launched it). – Werner Erasmus Mar 19 '16 at 13:55
  • @EJP.The named_semaphore solution works well, apart from the surprise that I got after clearing the windows event log. I'm now providing our own folder as solution (non default). I wrote the post to see if others had the same issues and what solution they preferred. – Werner Erasmus Mar 19 '16 at 14:01
  • None of this makes sense. If you're executing `wait()` you can't simultaneously be either orphaning the child or waiting for the wrong process. – user207421 Mar 20 '16 at 06:29
  • One can orphan the child easily by killing the parent by doing a kill -9 from the command line(external to program). But all this doesn't relate to the question. Also,a named semaphore is also used to prevent multiple instances from running. – Werner Erasmus Mar 20 '16 at 08:14

0 Answers0