bash - Preventing lock propagation -
bash - Preventing lock propagation -
a simple , seemingly reliable way locking under bash is:
exec 9>>lockfile flock 9
however, bash notoriously propagates such fd lock forked stuff including executed programs etc.
is there way tell bash not duplicate fd? it's great lock attached fd gets removed when programme terminates, no matter how gets terminated.
i know can stuff like:
run_some_prog 9>&-
but quite tedious.
is there improve solution?
you can utilize -o
command line alternative flock(1)
(long alternative --close
, might improve writing in scripts self-documenting nature) specify file descriptor should closed before executing commands via flock(1)
:
-o, --close close file descriptor on lock held before executing command. useful if command spawns kid process should not holding lock.
bash locking file-descriptor
Comments
Post a Comment