3 ms·
https://linux.die.net/man/1/flock https://linux.die.net/man/1/flock would probably help
by dymk 7y ago
https://linux.die.net/man/1/flock https://linux.die.net/man/1/flock would probably help
- fwip 7y agoA word of caution on flock: it may fail when used on some network filesystems, and it is tricky to make sure you've got it right. If you're locking on-disk it's pretty straight-forward, though.
- sirn 7y agoflock(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.