Determine if only one instance is running: Difference between revisions

added perl implementation
m (Fixed lang tags.)
(added perl implementation)
Line 120:
 
The standard library of OCaml also provides a [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Mutex.html Mutex] module.
 
=={{header|Perl}}==
The INIT block is runned just before the Perl runtime begins execution. See [http://perldoc.perl.org/perlmod.html perlmod]
 
Then it tries to get a lock to its own file, from where the script was called.
<lang perl>use Fcntl ':flock';
 
INIT
{
die "Not able to open $0\n" unless (open ME, $0);
die "I'm already running !!\n" unless(flock ME, LOCK_EX|LOCK_NB);
}
 
sleep 60; # then your code goes here</lang>
 
=={{header|Python}}==
Anonymous user