DynGig::Util::LockFile::PID - pid lock with an advisory file
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; }
Attempts to acquire lock. Returns pid if successful. Returns undef otherwise.
Returns the handle of the lock file.
Returns ID of process that owns the lock. Returns 0 if not locked.
Fcntl
See DynGig::Util
To install DynGig::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DynGig::Util
CPAN shell
perl -MCPAN -e shell install DynGig::Util
For more information on module installation, please visit the detailed CPAN module installation guide.