Removing Pending IPC OBJECTS (System V)

Dec 23, 2019 at 9:33am
Hello Guys.. i looked for an answare to my question online.. but nothing has been found.. Maybe because there's no an answare to my question??
By the way this is my question:


Working with IPC Objects (System V), i've seen that if a SIGINT (of something else) stop my Process, all IPCs Object opened will be pending.
Is there a way to implement a set of instruction that delete the opened IPC Object from the interrupted Process?.

Thanks guys.
Last edited on Dec 23, 2019 at 10:49am
Dec 23, 2019 at 10:37am
¿which library?
Dec 23, 2019 at 10:50am
I use System V IPC Objects.

I usually include sys.sem/ipc...
Dec 23, 2019 at 3:02pm
Add a signal handler for SIGINT.

Either clean up directly in the signal handler, or set a flag indicating that main() should do some cleanup of it's own.

http://man7.org/linux/man-pages/man7/signal-safety.7.html
Dec 23, 2019 at 3:22pm
I can use a signal handler, yes.. but when process stops critically?
I can't clean the IPC Objects with a new execution.. because i cant know the previou key_t returned..

I was looking for a way to get all opened memory segment (and then close it) but even this case is not possible, there's some memory segment used by OS.
Dec 23, 2019 at 3:32pm
What does "stops critically" mean?

Dec 23, 2019 at 3:45pm
A SIGKILL.. but not necessary a signal..
For example if im testing a source, and i forgot to detach some IPC segment?
I run this source 10 times and i generate 200 IPC Object..
What i thought was: "If i can clean all IPC Object left opened at the new source run?"
I thought to use a file that store all KEY_T opened object and then cleaning with a new RUN..
Dec 24, 2019 at 2:47pm
The signal handler will get you most of the way there. The remaining problems are if you get a SIGKILL or encounter an error while trying to do the cleanup.

You could store some recovery data (the KEY_T that you mention?) in a recovery file. When you shutdown normally, you delete the file. When you start up, see if the file exists. If so then you know that the previous instance exitted unexpectedly and you can use the data in the file to clean up.

Be sure to flush the recovery file (and possibly sync() it) when you're done writing to it. You don't want the process to crash with the recovery data still unflushed.
Dec 24, 2019 at 3:18pm
Thanks all guys! ;)
Topic archived. No new replies allowed.