Paranoid::IO::Lockfile(3pm)

Paranoid::IO::Lockfile3pm

Paranoid lockfile support

Usage

  use Paranoid::IO::Lockfile;
  use Fcntl qw(:flock);  # only needed if you use plock in lieu 
                         # of the other functions
  $rv = plock($lockfile);
  $rv = plock($lockfile, LOCK_SH | LOCK_NB);
  $rv = plock($lockfile, LOCK_SH | LOCK_NB, $mode);
  $rv = pexclock($lockfile);
  $rv = pshlock($lockfile);
  $rv = punlock($lockfile);

Version

$Id: lib/Paranoid/IO/Lockfile.pm, 2.10 2022/03/08 00:01:04 acorliss Exp $

Overview

This module provides convenience functions for using a lockfile to coordinate multi-process activities. While basically just a thin wrapper for Paranoid::IO functions it removes the small tedium of having to perform the multiple opens required to ensure all processes are working off the same files while avoiding race conditions.

Import lists

This module exports the following symbols by default:

    plock pexclock pshlock punlock

The following specialized import lists also exist:

    List        Members
    --------------------------------------------------------
    all         @defaults

Subroutines/methods

plock

  $rv = plock($filename);
  $rv = plock($filename, LOCK_EX);
  $rv = plock($filename, LOCK_EX, 0666);

Creates or opens the requested file while applying the lock condition. The lock type defaults to LOCK_EX if omitted, while the file permissions default to 0660. As always, umask applies.

There is one scenario in which one would want to use plock in lieu of pexclock, etc: if you wish to perform non-blocking lock attempts. All convenience functions are blocking.

pexclock

  $rv = pexclock($filename);
  $rv = pexclock($filename, $mode);

A wrapper for plock($filename, LOCK_EX).

pshlock

  $rv = pshlock($filename);
  $rv = pshlock($filename, $mode);

A wrapper for plock($filename, LOCK_SH).

punlock

  $rv = punlock($filename);
  $rv = punlock($filename, $mode);

A wrapper for plock($filename, LOCK_UN). This does not close the open file handle to the lock file. For that you need to call Paranoid::IO's pclose function.

Dependencies

o

Fcntl

o

Paranoid

o

Paranoid::Debug

o

Paranoid::IO

Bugs and limitations

Releases

5 releases since Debian 9 (Stretch); the text changed 4 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13

Author

Arthur Corliss ([email protected])

From libparanoid-perl 2.10-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.