4 ms·
flock(1) is not POSIX, though. mkdir(1) can be used if you absolutely want a POSIX way to manage locks. For example: if ! mkdir .lock; then printf
by sirn 7y ago
flock(1) is not POSIX, though. mkdir(1) can be used if you absolutely want a POSIX way to manage locks. For example:
if ! mkdir .lock; then
printf >&2 "Already running?\\n"
exit 1
fi
Some network file system implementation do not guarantee atomic mkdir, so you still need an extra caution with this method.
- posix_me_less 7y agoExistence of a file is an unreliable indicator of script instance running. Much more reliable is to search the script name or other characteristic in the list of running processes. To use this, the script has to have unique name though.