shmdt() — Shared memory detach operation

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE
#include <sys/shm.h>

int shmdt(const void *shmaddr);

General description

The shmdt() function detaches from the calling process's address space the shared memory segment located at the address specified by the argument shmaddr.

Storage in the user address space for a segment with the __IPC_SHAREAS attribute is not cleaned up unless the segment is no longer attached to by other processes in the address space.

Returned value

If successful, shmdt() decrements the value of shm_nattach in the data structure associated with the shared memory ID of the attached shared memory segment and returns 0.

If unsuccessful, shmdt() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
The value of shmaddr is not the data segment start address of a shared memory segment.

Related information