Determine if only one instance is running: Difference between revisions

Content added Content deleted
(Added BaCon version.)
Line 40: Line 40:
=={{header|AutoHotkey}}==
=={{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.
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|BaCon}}==
Using advisory locks from libc.
<lang bacon>PRAGMA INCLUDE <sys/file.h>
OPTION DEVICE O_NONBLOCK

OPEN ME$ FOR DEVICE AS me

IF flock(me, LOCK_EX | LOCK_NB) <> 0 THEN
PRINT "I am blocked, exiting..."
END
ENDIF

PRINT "Running this program, doing things..."
SLEEP 5000

CLOSE DEVICE me</lang>


=={{header|Bash Shell}}==
=={{header|Bash Shell}}==