title: Linux file locking
body: <p>Problem: on Linux platform create new file or overwrite an existing file so that other processes can open it for reading only. Using <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx" rel="nofollow noreferrer"><code>CreateFile</code></a> one could do something like this:</p>
  
  <pre><code>CreateFile("blah.log", GENERIC_WRITE, FILE_SHARE_READ,
             NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  </code></pre>
  
  <p>This call will fail to overwrite an existing file if it was opened by another process with similar flags.</p>
  
  <p>How to achieve similar behavior on Linux? Assume that advisory locks are respected by all programs.</p>