I am working on a university assignment, based largely around IPC and shared memory. The problem is, as a complete noob to C, I’ve been happily testing my app (which uses shmget and shmat obviously) for hours. As you can probably guess, I’ve not been cleaning up after myself, and now I can’t run my app, because (I assume) shmget cant allocate anymore resources.
My question is: how can I get this resource back without restarting OSX, and is there a GUI tool or something I can use to monitor/manage this shared memory I am creating?
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 withshmctl(id, IPC_RMID, NULL).From outside your application, the only option I can think of right now to clear your shared memory segments is:
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.)