According to the fcntl manual, fcntl locking with start=0, len=0, whence=2 should lock the byte range starting from the end of file (whence=2), with offset 0 (start=0) until the end of file (len=0), which in my mind means locking in total 0 bytes from EOF to EOF.
In this case I would expect that locking with those arguments would not lock anything. However, if I try (using python wrapper fcntl
), the following code does lock something, and the second copy is waiting for the first to finish:
f = open('some_file', 'a+')
fcntl.lockf(f, fcntl.LOCK_EX, 0, 0, 2)
print('got the lock')
time.sleep(100)
Similarly, the code with parameters whence=2, offset=100, len=0 also works, even those in this case the byte range is backwards [EOF + 100, EOF].
What am I locking?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…