title: Notify/Signal when memory mapped file modified
body: <p>I am currently sharing data (&lt;1KB) between multiple processes by memory-mapping. 1 "writer" process and multiple "reader" processes all <a href="http://linux.die.net/man/2/mmap" rel="noreferrer"><strong>mmap</strong></a> the same file.</p>
  
  <p>Currently the reader processes need to constantly keep checking for updates. The reader processes keep polling the mmap-ed region to see if any new data is written.</p>
  
  <p><strong>Typical Usage (and existing implementation)</strong>:<br>
  The "Writer" process is a logger which keeps appending new data (each on a new line) at irregular intervals. At any given point of time there can be one or more "reader" processes that are interested in any new data that the "writer" process generates. Also rather than having an indefinitely extending file, its is a circular buffer i.e. after a fixed number of lines the writer loops-back and start overwriting the file from the beginning with the new data. A header field in this file keeps track of position of the latest data i.e. the current "head".</p>
  
  <p>In short the systems attempts to mimic the semantics of <strong>msgsnd()</strong> &amp; <strong>msgrcv()</strong> with two additional caveats:</p>
  
  <ol>
  <li><p><strong>Support multiple "readers"</strong><br>
  <em>When "writer" posts a single msg, multiple notifications should be sent, 1 for each
  active "reader".</em><br>
  --> Currently achieved as each "reader" constantly polls the "head" field and reads the new data when it changes.</p></li>
  <li><p><strong>Persistence(file backed)</strong><br>
  <em>If any "reader"/"writer" process is abruptly terminated, recovering the system should be as simple as restarting the process.</em><br>
  --> Currently achieved as the IPC shared data is maintained in an mmap-ed file backed on the disk.</p></li>
  </ol>
  
  <blockquote>
    <p>What would be a<br>
    - <strong>Fast</strong> (low latency) and<br>
    - <strong>Light-weight</strong> (low cpu-usage)   alternative to implement some sort of event mechanism to notify the reader processes every time the
    mmap-ed region is modified by the writer process?</p>
  </blockquote>
  
  <p><strong>NOTE</strong>: In the reader process, adding an <a href="http://linux.die.net/man/7/inotify" rel="noreferrer"><strong>inotify</strong></a> watch on the mmap-ed file did NOT result in any events when the mmap-ed memory was updated by the writer process (even after calling <a href="http://linux.die.net/man/2/msync" rel="noreferrer"><strong>msync()</strong></a>).</p>