title: Persisting Data Across Shared Library Calls in Linux
body: <p><strong>Background</strong></p>
  
  <p>I am developing a shared library that manages an embedded Ethernet switch.  This library is called by an assortment of switch-aware management applications and is designed to be the only interface to the device.  The particular switch in question is designed for enterprise applications and expects the controlling CPU to manage much of the internal state.  To do this, I need to store a table of data that will persist across multiple calls of the library from different applications.</p>
  
  <p>To this end, I have been considering shared memory with the appropriate concurrency guards. This, however raises a number of questions due to the dynamic nature of a shared library.</p>
  
  <p><strong>Questions</strong></p>
  
  <p>(1)  Does there always need to be a running process to retain this memory?</p>
  
  <p>(2)  Since my library is constantly being loaded and unloaded, what happens when all calls exit?  Who "owns" the memory at that point or does it leak?</p>
  
  <p>(3)  Is there a better system to persist an array of <code>struct</code>s across multiple calls of my library (I had considered flat files but filesystem access is quite limited).</p>
  
  <p><strong>Additional Information</strong></p>
  
  <ul>
  <li><p>Individual calls to the library are atomic and independent.</p></li>
  <li><p>The library has no dependencies and does not <code>fork</code> any children.</p></li>
  <li><p>The data being tracked needs to be maintained for the entire boot time of the unit.</p></li>
  <li><p>The platform is a custom version of the 3.x Linux kernel.</p></li>
  <li><p>All code is being written in C with a focus on reusability and portability.</p></li>
  </ul>