Managing shared memory in C on OSX

I am working on a university assignment based mainly on IPC and shared memory. The problem is, as a complete noob for C, I enjoyed testing my application (which explicitly uses shmgetand shmat) for several hours. As you probably can guess, I’m not cleaning up after myself, and now I can’t start my application because (I suppose) shmgetI can’t allocate more resources.

My question is: how can I return this resource without restarting OSX, and is there a GUI tool or something that I can use to monitor / manage this shared memory that I create?

+3
source share
2 answers

Call shmdt("shared memory sharing") in the shared memory segment in each process that contains a link to it. Unix shared memory sections are counted by reference, so when the last process is separated from them, they can be destroyed using shmctl(id, IPC_RMID, NULL).

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

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

but this is a terribly ineffective coolge. (I'm also not sure if it works, but not Linux, but Linux violates the Unix standard, while MacOS X is certified against it.)

+1
source

Maybe a little late, but there are cmdline tools available for this. ipcs and ipcrm

Take a look at the pages of your employees.

+3

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


All Articles