I have a file. My application must open it and protect it from writing done by other applications in my operating system.
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.
Test example
#!/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)
How can I lock a file for every application in system except mine?
 
    