What happens to interprocess memory if one of the processes dies unexpectedly?
c++, linux, shared-memory
Solution
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)
Problem
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 answer for Win also) when one of the procs die? Is it UB?