#!/usr/bin/perl use strict; use warnings; use Fcntl qw/:DEFAULT :flock/; open(SELF, '<', $0) or die "Unable to open '$0' for reading: $!"; flock SELF, LOCK_EX | LOCK_NB or exit; print "I must be the only process running\n"; sleep 300; #### #!/usr/bin/perl use strict; use warnings; use Fcntl qw/:DEFAULT :flock/; flock DATA, LOCK_EX | LOCK_NB or exit; print "I must be the only process running\n"; sleep 300; __DATA__