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

NAME

File::Lock::ParentLock - share lock among child processes of given pid.

SYNOPSIS

my $locker= File::Lock::ParentLock->new( -lockfile=>$lockfile, -pid=>$pid, );

die $locker->status_string() if !$locker->lock(); ... die $locker->status_string() if !$locker->unlock();

DESCRIPTION

File::Lock::ParentLock is useful for shell scripting where there are lots of nested script calls and we want to share a lock through the parent - child relationship.

METHODS

new

Create a File::Lock::ParentLock. Options:

-lockfile

Lockfile name to be created. A relative path will be converted to the absolute path at the moment script called. Default is .lock.

-pid

PID to store in lock / to access a lock. Default is current PID.

lock

Accuire Lock.

If supplied PID is a child of PID stored in the lock file then access is granted (the lock is accuired). If the lock file does not exist or is invalid, the lock file will be created and the supplied PID will be stored in the lock file, If supplied PID is not a child of the PID stored in the lock file, then access is denied.

Returns true if the lock is successfully accuired.

unlock

Release lock.

Lock is successfully released if supplied PID is a child of the stored PID. Also, if supplied PID is the same as PID stored in the lock file then the lock file will be removed.

Returns true if lock is successfully released. Returns false if supplied PID is not a child of the stored PID or some other error happen.

can_lock

Test whether lock can be accuired. Returns true if lock can be accuired.

is_locked_by_us

Test whether lock is accuired by us or by our parent process.

is_locked_by_others

Test whether lock is accuired by a live process that is not us or our parent process.

is_locked

Test whether lock is accuired by us or by our parent process. Deprecated. Use is_locked_by_us instead.

status_string

Returns the human readable string regarding the status of locking.

lockfile

Accessor method. Returns the object's lockfile.

pid

Accessor method. Returns the object's pid.

parentlock_lock, parentlock_unlock, parentlock_is_locked, parentlock_is_locked_by_us, parentlock_is_locked_by_others, parentlock_can_lock, parentlock_status_string

Procedural interface. Same as lock, unlock, is_locked, is_locked_by_us, is_locked_by_others, can_lock, status_string But require a pair ($lockfile,$pid) instead of the object.

AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

ACKNOWLEGEMENTS

To Alexey Torbin <at@altlinux.org>, whose qa-robot package had a strong influence on repocop.

COPYRIGHT AND LICENSE

Copyright (c) 2008-2018 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available or under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.