Managing Shared Memory in C on OSX Managing Shared Memory in C on OSX unix unix

Managing Shared Memory in C on OSX


Perhaps a bit late, but there are cmdline tools available to do exactly this. ipcs and ipcrm

take a look at their man pages.


Call shmdt ("shared memory detach") on the shared memory segment in each process that holds a reference to it. Unix shared memory sections are reference counted, so when the last process detaches from them, they can be destroyed with shmctl(id, IPC_RMID, NULL).

From outside your application, the only option I can think of right now to clear your shared memory segments is:

for (int id=0; id < INT_MAX; id++)    shmctl(id, IPC_RMID, NULL);

but this is a horribly inefficient kludge. (I'm also not sure if it works; it doesn't on Linux, but Linux violates the Unix standard while MacOS X is certified against it.)