Manuel Selva
Manuel Selva

Reputation: 19050

Cleanly destroy a System V shared memory segment

I am using shmget, shmat and shmctl to respectively get and create a shared memory segment, attach it in processes address space and remove it.

I am wondering if processes can still use the shared memory segment even if it has been detached and asked for removal using

shmctl(id, IPC_RMID, ...)

in one process.

I am not able to get the information from the man page:

IPC_RMID Mark the segment to be destroyed. The segment will only actually be destroyed after the last process detaches it (i.e., when the shm_nattch member of the associated structure shmid_ds is zero). The caller must be the owner or creator, or be privileged. If a segment has been marked for destruction, then the (nonstandard) SHM_DEST flag of the shm_perm.mode field in the associated data structure retrieved by IPC_STAT will be set.

Upvotes: 4

Views: 1053

Answers (1)

linuxchip
linuxchip

Reputation: 316

On Linux, it is possible to attach a shared memory segment even if it is already marked to be deleted. However, POSIX.1-2001 does not specify this behavior and many other implementations do not support it.

Upvotes: 1

Related Questions