Jump to content

Determine if only one instance is running: Difference between revisions

no 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}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.