gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:28:29 25 4
gpt4 key购买 nike

我只是想知道。我在两个不同的服务器上有两个进程。这些进程将信息写入同一个文件,并通过 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).

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

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

关于linux - 当我通过 fcntl 锁定位于远程存储上的文件时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34464880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com