title: How to lock file from write operations of other applications in operating system?
body: <p>I have a file. My application must open it and protect it from writing done by other applications in my operating system.</p>
  
  <p>Is it possible to do such thing? I tried fcntl.flock() but it seems that this lock is working only for my application. Other programs like text editors can write to file without any problems.</p>
  
  <p>Test example</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import time
  import fcntl
  
  with open('./somefile.txt', 'r') as f:
      # accquire lock
      fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
  
      # some long running operation
      # file should be protected from writes
      # of other programs on this computer
      time.sleep(20)
  
      # release lock
      fcntl.flock(f, fcntl.LOCK_UN)
  </code></pre>
  
  <p>How can I lock a file for every application in system except mine?</p>