Anonymous user
Determine if only one instance is running: Difference between revisions
Determine if only one instance is running (view source)
Revision as of 18:17, 19 February 2020
, 4 years agono edit summary
No edit summary |
|||
Line 40:
=={{header|AutoHotkey}}==
AutoHotkey has a #SingleInstance command. If you run two scripts that don't have it at the same time, it alerts the user. #SingleInstance FORCE closes the older instance when a newer one is run, and #SingleInstance IGNORE does nothing when you try to open a new instance of an already-running script.
=={{header|Bash Shell}}==
Using flock, exits 0 if you got the lock, otherwise exits 1, below is a simplified example:
<lang bbcbasic>
local fd=${2:-200}
# create lock file
eval "exec $fd>/tmp/my_lock.lock"
# acquire the lock, or fail
flock -nx $fd \
&& # do something if you got the lock \
|| # do something if you did not get the lock
</lang>
There's a nice program called singleton that wraps this in an easy to use package : https://github.com/krezreb/singleton
=={{header|BBC BASIC}}==
|