Do flock locks reset after a system restart?

混江龙づ霸主 提交于 2020-08-08 05:18:06

问题


Let's say the system powers down unexpectedly due to a power outage.

Are flock locks always considered to be "unlocked" when the system starts up?

On Linux, flock relies on fcntl(...) (file descriptors).

Asked another way: Is it unnecessary to manually call flock -u <lock_filename> when the system first starts up? (i.e. from cron @reboot)?

Update:

BSD flock man pages says:

Locks are on files, not file descriptors.   That is, file descriptors
duplicated  through dup(2) or fork(2) do not result in multiple instances
of  a lock, but rather multiple references to a single lock.

回答1:


My Linux guru friend here mentions that there is a kernel locks table (for file locks) (usually stored in memory) which disappears on a reboot.

And that the file lock is just there for as long as the process is running.




回答2:


According to the linux man page:

Locks created by flock() are associated with an open file table entry.

This is a data structure in the kernels memory and not in the file system that may be on persistent disk storage.

Open files are closed when the process exits - thus flocks are valid only as long as a process holding it is running.



来源:https://stackoverflow.com/questions/20070943/do-flock-locks-reset-after-a-system-restart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!