File::Lock::ParentLock - share lock among child processes of given pid.
my $locker= File::Lock::ParentLock->new( -lockfile=>$lockfile, -pid=>$pid, );
die $locker->status_string() if !$locker->lock(); ... die $locker->status_string() if !$locker->unlock();
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.
Create a File::Lock::ParentLock. Options:
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.
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.
Test whether lock can be accuired. Returns true if lock can be accuired.
Test whether lock is accuired by us or by our parent process.
Test whether lock is accuired by a live process that is not us or our parent process.
Test whether lock is accuired by us or by our parent process. Deprecated. Use is_locked_by_us instead.
Returns the human readable string regarding the status of locking.
Accessor method. Returns the object's lockfile.
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.
Written by Igor Vlasenko <firstname.lastname@example.org>.
To Alexey Torbin <email@example.com>, whose qa-robot package had a strong influence on repocop.
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.