title: How can I delete unused shared memory and semaphores?
body: <p>Similar to: <a href="https://stackoverflow.com/questions/2143404/delete-all-shared-memory-and-semaphores-on-linux">Delete all shared memory and semaphores on Linux</a> however, I want to do so in C, not with some script.</p>
  
  <p>My specific problem: in linux + mac, when I debug a program and terminate it mid process, the shared resources (memory + semaphores) arent released. My program does some client server stuff where the server is the first process to acquire the shared resources. Therefore, after a termination without detaching, when I restart the program, it assumes that it is the client when there is no server (because the resource has been created and not released).</p>
  
  <p>Currently, I am using Qt to manage the shared resources but Qt does not appear to have a way to deal with this situation (the error code that create returns is that the resource has already been created). Therefore, Im looking to a more OS specific way to do this. NOTE: windows does not have this problem because the shared resource is released on termination automatically.</p>