# This is a trick used to prevent concurrent applications
# from running, but that will work WITHOUT needing pid
# or lock files, and so is kill -9 or power failure safe.
# To work it needs a __DATA__ section to be defined at
# the end of the file.
use Fcntl 'LOCK_EX', 'LOCK_NB';
unless ( flock DATA, LOCK_EX | LOCK_NB ) {
# An existing instance of this application is already running
print STDERR "Program is already running\n";
exit(0);
}
__DATA__
Used as a lock to prevent concurrent execution.
Do not remove this data section.
Of course, I'm not sure how well it would work on Win32, but I'm sure there's an equivalent |