Message queue removal?
Hi,
I'm sending this to debian-user with the hope that someone with the
"know-how" will see it. I'm writing a program which will use SysV IPC
type message queues and shared memory for communication between parent
and children. I want the application to be "nice" and clean up after
itself, and to make sure that shm/msgqueue is cleaned up (even if the
program segfaults).
For SHM I do the following:
Parent process creates shm segment, attaches to it, and then uses shmctl
to mark the segment for removal which means it will be removed when the
number of attaches reaches zero. This works just fine for segfaults,
normal exits etc.
Now for msgqueues I've had a few ideas:
o fork a separate process that checks the status of the other processes
and removes the queue at an appropriate time. Not ideal since the
"watcher" could segfault/be killed/whatever.
o Register an atexit function and signal handlers for all error signals.
This would mean lots of registered handlers, negative effects? Could
it capture *all* exit conditions?
o Start the program with some kind of wrapper script which "somehow"
gets the ID of the queue and then makes sure its removed when the
program exits. Advantages? Disadvantages? Does it work?
o Other suggestions?
How does other message queue using programs handle this?
Thanks in advance,
David
PS
Please CC any reply to my email address
Reply to: