The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNPOSIS

 use DynGig::Util::LockFile::PID;
 
 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