Deleting shared memory with ipcrm in Linux

ぃ、小莉子 提交于 2019-12-01 14:58:42

I vaguely remember from my UNIX (AIX and HPUX, I'll admit I've never used shared memory in Linux) days that deletion simply marks the block as no longer attachable by new clients.

It will only be physically deleted at some point after there are no more processes attached to it.

This is the same as with regular files that are deleted, their directory information is removed but the contents of the file only disappear after the last process closes it. This sometimes leads to log files that take up more and more space on the file system even after they're deleted as processes are still writing to them, a consequence of the "detachment" between a file pointer (the zero or more directory entries pointing to an inode) and the file content (the inode itself).

You can see from your ipcs output that 3 of the 4 still have attached processes so they won't be going anywhere until those processes detach from the shared memory blocks. The other's probably waiting for some 'sweep' function to clean it up but that would, of course, depend on the shared memory implementation.

A well-written client of shared memory (or log files for that matter) should periodically re-attach (or roll over) to ensure this situation is transient and doesn't affect the operation of the software.

You said that you used the following command

ipcrm -M 0x0000162e (this is the key)

From the man page for ipcrm

 -M shmkey
         Mark the shared memory segment associated with key shmkey for
         removal.  This marked segment will be destroyed after the
         last detach.

So the behaviour of -M options does exactly what you observed, ie set the segment to be destroyed only after the last detach.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!