The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

parentlock - share parent's lock with child processes.

SYNOPSIS

parentlock [-v] [--lock | --unlock | --is-locked-by-us | --is-locked-by-others] [--status] [--lockfile] lockfile [-p|--pid] PID

DESCRIPTION

parentlock is useful for shell scripting where there are lots of nested script calls and we want to share a lock from the main wrapper script for its subprocesses through the parent - child relationship.

Note that unlocking is optional because the lock becomes invalid when the process whose pid is contained in the lock dies.

EXAMPLES

In each chell script add at the beginning

 #!/bin/sh
 LOCKFILE=/workdir/.lock
 parentlock --lock --lockfile $LOCKFILE $$ || exit 1
 ...

Optionally, add at the end of the script, to clean up stale lock file:

 ...
 parentlock --unlock --lockfile $LOCKFILE $$

OPTIONS

-l,--lock

Lock

-u,--unlock

Unlock

--is-locked-by-us

Query about existing lock. Returns true if it is locked by PID or its parent. Return false ottherwise.

--is-locked-by-others

Query about existing lock. Returns true if is locked by a live process not related to PID. Return false ottherwise.

--status

Print the lock status against the parent pid PID.

-p,--pid

PID to lock with.

-f,--file,--lockfile path

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

-v,--verbose

Increase verbosity level.

-q,--quiet

Silent mode.

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.

COPYING

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

This is free software; you can redistribute it and/or modify it 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.