if you are interested in motivation Ill elaborate it in next few sentences, if not just skip to the Q.
I was thinking about making fast logger but the one that is not affected when program crashes(aka few last log msgs arent lost). So my idea is to write to the shared memory(ringbuffer) and have another low prio process read from it and do the dumping. But for that to work I need to know what happens to shared memory if one process exits(normal exit, SEGFAULT)...
So my question is: What happens to shared memory (in Linux, but you can A for Win also) when one of the procs die? Is it UB?
What happens to shared memory (in Linux, but you can A for Win also) when one of the procs die?
Nothing. When a process dies, the shared memory is left as it is. It is mapped as a file under /dev/shm/
directory. It is removed either when the system reboots, or when all processes unmmap the shared memory file and the shm_unlink()
is called.
Is it UB?
No, it is well defined. See the man page for shm_overview(7) :
POSIX shared memory objects have kernel persistence: a shared memory object will exist until the system is shut down, or until all processes have unmapped the object and it has been deleted with shm_unlink(3)
Read boost IPC mechanisms, they explain persistence concept about shared memory.
http://www.boost.org/doc/libs/1_53_0/doc/html/interprocess/some_basic_explanations.html#interprocess.some_basic_explanations.persistence
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With