flock:什么时候使用 -o (--close) 选项?

flock: when to use the -o (--close) option?

根据flock手册,-o--close选项是这样描述的:

Close the file descriptor on which the lock is held before executing command. This is useful if command spawns a child process which should not be holding the lock.

我不明白这在实践中意味着什么。您能否提供一些示例 commands/scenarios 此选项在哪些方面会有所帮助?

我只是想自己确定一下!手册页没有提供明确的描述:

   -o, --close
         Close the file descriptor on which the lock is held before executing command.  This is useful if command spawns a child process which should not be holding the lock.

我的问题是...如果您在命令执行之前释放锁,那么锁有什么意义?我在这里找到了答案:https://utcc.utoronto.ca/~cks/space/blog/linux/FlockUsageNotes

它指出:

flock -n -o LOCKFILE SHELL-SCRIPT [ARGS ...]

Run this way, the only thing holding the lock is flock itself. When flock exits (for whatever reason), the file descriptor will be closed and the lock released, even if SHELL-SCRIPT is still running.