在Linux 中的bash 脚本中,我使用flock [命令flock,而不是系统调用flock()] 来实现文件锁定,从而防止共享资源[这是tmpfs 中的文件] 的并发访问。
我有陷阱处理程序来处理脚本的异常终止:trap "{ rm -rf $LOCK ; rm -rf $TMPFS_FILE; exit 255; }" SIGINT SIGTERM
其中 $LOCK 是我的锁定文件,$TMPFS_FILE 是我的共享资源。
我的问题是我是否还需要明确执行文件解锁?或者 Linux 是否会在所有程序终止(自愿终止和强制终止)情况下为我执行此操作?
From man 1 flock http://linux.die.net/man/1/flock:
-u,--解锁
Drop a lock. This is usually not required, since a lock is
automatically dropped when the file is closed. However, it may
be required in special cases, for example if the enclosed com‐
mand group may have forked a background process which should not
be holding the lock.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)