How to handle getting killed (kill -9) while using Shared Memory?
<p>I am using Shared Memory in a Client-Server Model.
When my Server gets killed off by the user by using sigkill instead of sigterm / sigint I can't do anything about it (as intended), but my Shared Memory Object and Semaphores still exist in /dev/shm/.</p>

<p>The next time I start my Server I want to create a new object with exactly the same name, and - as intented - this fails and I exit my program.</p>

<p>The user would need to remove the objects on his own - which is certainly not the best thing. </p>

<p>How can I handle this?</p>

<p>I could just call shm_open() without the O_EXCL flag, ultimately destroying the purpose of this flag. Because maybe there is already an instance of my server running and uses this object.</p>

<p>Pulseaudio seems to use a combination of digits to keep it's objects distinct and doesn't get affected by killing it with -9, so there seems to be a way.</p>