The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

NAME

DynGig::Util::LockFile::PID - pid lock with an advisory file

SYNPOSIS

my $file = '/lock/file/path';
my $lock = DynGig::Util::LockFile::PID->new( $file );
my $pid = $lock->lock();
if ( $pid )
{
if ( my $child = fork() )
{
my $handle = $lock->handle();
syswrite $handle, $child;
exit 0;
}
## child safely does critical stuff
}
else
{
my $pid = DynGig::Util::LockFile::PID->check( $file );
die "another instance $pid already running\n" if $pid;
}

DESCRIPTION

lock()

Attempts to acquire lock. Returns pid if successful. Returns undef otherwise.

handle()

Returns the handle of the lock file.

check( $filename )

Returns ID of process that owns the lock. Returns 0 if not locked.

SEE ALSO

Fcntl

NOTE

See DynGig::Util