Skip to content

Share Memory in Linux using C

Is it safe to use shm_unlink even there are other process currently open the shared memory?

For exmaple:

Process B shm_open and then Process A shm_unlink. Is it ok for Process B?



Yes, it is safe to call shm_unlink if another process has it opened. Per the man page for shm_unlink:

The operation of shm_unlink() is analogous to unlink(2): it removes a shared memory object name, and, once all processes have unmapped the object, de-allocates and destroys the contents of the associated memory region. After a successful shm_unlink(), attempts to shm_open() an object with the same name will fail (unless O_CREAT was specified, in which case a new, distinct object is created).