Clear OS X shared memory

I use memory between the parent process and several child processes, allocating shared memory segments using shm_open / mmap in OS X. Any parent or children can create a segment and then report an identifying name. I understand that a parent must call shm_unlink on each of these segments when it finishes working in memory cleanup, otherwise shared memory is constantly leaking out.

What I initially thought after reading the documentation is that shared segments are cleared when no processes are displayed with it. However, experiments show that this is not the case, and someone should explicitly use shm_unlink.

Is there any way in OS X to list all existing shared memory segments? The problem is that the parent may crash and therefore has no chance to call shm_unlink. On Linux, my solution is to clear / dev / shm, but on OS X, I need some way to publish open shared segments.

+4
source share
2 answers

The answer seems to be: you cannot.

First, see the question , which quotes a comment in the kernel:

  • TODO:
    (2) You need to export data to a user tool through Sysctl. Should ipcs (1) and ipcrm (1) be expanded or should there be new tools for managing both the POSIX kernel semaphores and the shared POSIX memory is written?

Also see this post on the Apple unix-porting mailing list:

There is no "picps"/"picprm" utility, you are expected to remember what you create and clean up afterward, or clean up first thing on restart if you crash a lot, there is nothing exposed directly in the filesystem namespace, and you are expected to do the shm_unlink because it is a rendezvous for potentially a lot of unrelated programs. 
+3
source

I hope you find out your problem. you can use ipcs -a and look under the heading "Shared memory" for NATTCH. this value will show you how many guys are tied to a specific identifier.

0
source

Source: https://habr.com/ru/post/1502652/


All Articles