当我通过 fcntl 锁定位于远程存储上的文件时会发生什么?

What happen when I lock file located on remote storage via fcntl?

我只是想知道。我在两个不同的服务器上有两个进程。 这些进程将信息写入同一个文件,并通过 fcntl 使用锁定进行同步。如果其中一个进程将被中止并且它拥有文件锁会发生什么?如何通知 NFS 服务器此进程已死亡?

阅读http://man7.org/linux/man-pages/man2/fcntl.2.html

Record locking and NFS Before Linux 3.12, if an NFSv4 client loses contact with the server for a period of time (defined as more than 90 seconds with no communication), it might lose and regain a lock without ever being aware of the fact. (The period of time after which contact is assumed lost is known as the NFSv4 leasetime. On a Linux NFS server, this can be determined by looking at /proc/fs/nfsd/nfsv4leasetime, which expresses the period in seconds. The default value for this file is 90.) This scenario potentially risks data corruption, since another process might acquire a lock in the intervening period and perform file I/O.

Since Linux 3.12, if an NFSv4 client loses contact with the server,any I/O to the file by a process which "thinks" it holds a lock will fail until that process closes and reopens the file. A kernel parameter, nfs.recover_lost_locks, can be set to 1 to obtain the pre-3.12 behavior, whereby the client will attempt to recover lost locks when contact is reestablished with the server.Because of the attendant risk of data corruption, this parameter defaults to 0 (disabled).

如果进程终止,则进程持有的所有锁都将被释放。

我认为这是您所期望的答案