彻底销毁System V共享内存段 [英] Cleanly destroy a System V shared memory segment
问题描述
我正在使用 shmget
, shmat
和 shmctl
分别获取和创建共享内存段,将其附加在进程地址空间中并删除它.
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, ...)
在一个过程中.
我无法从手册页中获取信息:
I am not able to get the information from the man page:
IPC_RMID
标记要销毁的网段.实际上,只有在最后一个进程将其分离后,该段才会被销毁(即,当关联结构shmid_ds
的shm_nattch
成员为零时).呼叫者必须是所有者或创建者,或具有特权.如果某个段已标记为要销毁,则shm_perm.mode
的(非标准)SHM_DEST
标志将设置由IPC_STAT
检索的关联数据结构中的字段.
IPC_RMID
Mark the segment to be destroyed. The segment will only actually be destroyed after the last process detaches it (i.e., when theshm_nattch
member of the associated structureshmid_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 theshm_perm.mode
field in the associated data structure retrieved byIPC_STAT
will be set.
推荐答案
在 Linux 上,即使共享内存段已经被标记为删除,也可以附加它.但是,POSIX.1-2001没有指定此行为,并且许多其他实现也不支持此行为.
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.
这篇关于彻底销毁System V共享内存段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!