title: How to lock/unlock a file across process?
body: <p>Using C# running on mono on Linux, notice that below code works well on windows can lock a file across process but not on linux via mono (ubuntu 14.04)</p>
  
  <pre><code>new FileStream("myfile.lock",FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None);
  </code></pre>
  
  <p>research from internet, i should be able to do it with <a href="http://www.thegeekstuff.com/2012/04/linux-file-locking-types/" rel="nofollow">advisory lock</a> </p>
  
  <pre><code>FileStream.Lock
  </code></pre>
  
  <p>however, it doesn`t work. tested with two processes on ubuntu 14.04, both of them can execute "FileStream.Lock(0, int.MaxValue)". i would expect the later one will fail with exception per <a href="https://github.com/mono/mono/blob/master/mcs/class/corlib/System.IO/FileStream.cs#L862" rel="nofollow">source code</a>.</p>
  
  <p>anyone know is there any solution?</p>