为什么 fcntl start=0, len=0, whence=2 有效?

Why fcntl start=0, len=0, whence=2 works?

根据 fcntl 手册,fcntl locking with start=0, len=0, whence=2 应该锁定从文件末尾(whence=2)开始的字节范围,偏移量为 0(start=0)直到文件末尾 (len=0),在我看来这意味着从 EOF 到 EOF 总共锁定 0 个字节。

在这种情况下,我希望使用这些参数锁定不会锁定任何东西。但是,如果我尝试(使用 python 包装器 fcntl),以下代码确实会锁定某些内容,并且第二个副本正在等待第一个副本完成:

f = open('some_file', 'a+')
fcntl.lockf(f, fcntl.LOCK_EX, 0, 0, 2)
print('got the lock')
time.sleep(100)

类似地,带有参数 whence=2、offset=100、len=0 的代码也可以工作,即使在这种情况下字节范围是向后的 [EOF + 100, EOF]。

我在锁定什么?

我做了一些测试,答案似乎如下 - whence=2 直到 EOF 才锁定,但直到无穷大,这是 not 我会如何阅读手册页中的描述:

Specifying 0 for l_len has the special meaning: lock all bytes starting at the location specified by l_whence and l_start through to the end of file, no matter how large the file grows.