in reply to Re^2: Mechanism for ensuring only one instance of a Perl script can only run?
in thread Mechanism for ensuring only one instance of a Perl script can only run?
Maybe I'm overlooking something, but given the following example code, it is not clear to me where there could occur a race condition.
#! /usr/bin/perl + use strict; use warnings; my $pidfile="testfile.pid"; my $scriptname = $0; my $pid="$$"; if(-e $pidfile) { open(PFH, '<', $pidfile) or die $!; $pid =<PFH>; close(PFH); print"$scriptname already running: pid is $pid"; exit; } open(PFH, '>', $pidfile) or die $!; print(PFH $$); close(PFH); # do the job + sleep 13; unlink($pidfile);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Mechanism for ensuring only one instance of a Perl script can only run?
by hv (Prior) on Dec 06, 2022 at 05:10 UTC | |
by afoken (Chancellor) on Dec 06, 2022 at 19:47 UTC | |
by hv (Prior) on Dec 07, 2022 at 03:06 UTC | |
by afoken (Chancellor) on Dec 07, 2022 at 19:17 UTC | |
by rizzo (Curate) on Dec 07, 2022 at 01:24 UTC |