Flock: Difference between revisions

45 bytes added ,  29 January 2022
(Created page with "Flock is a tool to prevent running a script multiple times. ==Usage== ===CLI=== ===In a bash script=== <syntaxhighlight lang="bash"> exec {lock_fd}>$LOCKFILE || exit 1 flock -n "$lock_fd" || { echo "Another instance is running" >&2 exit 1 } # Note that the fd will unlock automatically at the end of the script. # Unlock once all background processes are done. exec {lock_fd}>&- # Or unlock immediately flock -u "$lock_fd" </syntaxhighlight>")
 
 
Line 3: Line 3:
==Usage==
==Usage==
===CLI===
===CLI===
<pre>
flock -n $LOCKFILE $MY_COMMAND
</pre>
===In a bash script===
===In a bash script===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">