Skip to content

shm_unlink()

Purpose

Removes the name of a POSIX shared memory object.

#include <sys/mman.h>

Prototype

int shm_unlink(const char *name);

Parameters

  • name: POSIX shared memory object name, such as /demo_shm.

Return Value

  • Success: returns 0.
  • Failure: returns -1 and sets errno.

Minimal Example

shm_unlink("/demo_shm");

Common Pitfalls

  • shm_unlink() removes the name, but existing mappings remain valid until unmapped.
  • Use it during cleanup to avoid stale shared memory objects.
  • Coordinate cleanup when multiple processes may still attach.