gpt4 book ai didi

c - POSIX 文件锁是否可重入?

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

我正在通过 fcntl 使用 POSIX mandatory 文件锁。我想知道这些锁是否可重入,即。进程能否获取它已经拥有的锁?

最佳答案

通过fcntl 的建议锁是基于每个进程的,并且只是在给定进程的文件上累积锁定间隔。也就是说,由应用程序来跟踪时间间隔,任何针对某个时间间隔的解锁调用都会解锁它,而不管针对该时间间隔进行了多少次锁定调用。

更糟糕的是,关闭该文件的任何文件描述符都会取消对该文件的所有锁定:

As well as being removed by an explicit F_UNLCK, record locks are automatically released when the process terminates or if it closes any file descriptor referring to a file on which locks are held. This is bad: it means that a process can lose the locks on a file like /etc/passwd or /etc/mtab when for some reason a library function decides to open, read and close it.

关于c - POSIX 文件锁是否可重入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13220054/

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