title: Remove posix shared memory when not in use?
body: <p>Is there any way, linux specific or not, to have posix shared memory segments (obtained with <code>shm_open()</code>) removed when no process is using them. i.e. have them reference counted and have the system remove them when the reference becomes 0 </p>
  
  <p>A few notes:</p>
  
  <ul>
  <li><p>Establishing an atexit handler to remove them doesn't work if the program crashes.</p></li>
  <li><p>Currently, the linux specific way, I embed the pid in the segment name, and try to find unused segments by walking /dev/shm in an external program. Which has the drawback of having to periodically clean them up externally in a rather hackish way.</p></li>
  <li><p>As the program can run multiple copies, using a well defined name for the segment that the program reuses when it starts up is not feasible.</p></li>
  </ul>