Here is a simple example of using a dedicated lock file
my $LOCK_EX = 2; # exclusive lock on file
my $LOCK_UN = 8; # unlock file
my $lock_file = $ENV{ XYZ_DIR } . "/$0.lock";
open my $lh, ">$lock_file" || die "Can't open lock file $lock_file: $!
+";
flock $lh, $LOCK_EX; # will wait for exclusive lock
# on lock file
# do the exclusive actions
flock $lh, $LOCK_UN;
close $lh;
|