Arthur Corliss > Paranoid-0.36 > Paranoid::Lockfile

Download:
Paranoid/Paranoid-0.36.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  4
Open  1
View/Report Bugs
Module Version: 0.65   Source  

NAME ^

Paranoid::Lockfile - Paranoid Lockfile support

VERSION ^

$Id: Lockfile.pm,v 0.65 2011/12/08 07:53:07 acorliss Exp $

SYNOPSIS ^

  use Paranoid::Lockfile;

  $rv = plock($lockfile);
  $rv = punlock($lockfile);
  $rv = pcloseLockfile($lockfile);

DESCRIPTION ^

This modules provides a relatively safe locking mechanism across multiple processes. This does not work over NFS or across remote systems, this is only intended for use on a single system at a time, and only on those that support flock.

sysopen is used to avoid race conditions with multiple process attempting to create the same file simultaneously.

SUBROUTINES/METHODS ^

plock

  $rv = plock($filename);

This function attempts to safely create or open the lockfile. It uses sysopen with O_CREAT | O_EXCL to avoid race conditions with other processes. Returns a true if successful.

Your can pass an optional second argument which would be a string of either 'write' or 'shared'. The default is 'write', which locks the file in exclusive write mode.

You can pass an optional third argument which would be the lockfile filesystem permissions if the file is created. The default is 0600.

NOTE: This function will block until the advisory lock is granted.

punlock

  $rv = punlock($filename);

This function removes any existing locks on the specified filename using flock. If no previous lock existed or it was successful it returns true. This does not, however, close the open filehandle to the lockfile.

pcloseLockfile

  $rv = pcloseLockfile($filename);

This function releases any existing locks and closes the open filehandle to the lockfile. Returns true if the file isn't currently open or the operation succeeds.

DEPENDENCIES ^

o

Fcntl

o

Paranoid

o

Paranoid::Debug

BUGS AND LIMITATIONS ^

AUTHOR ^

Arthur Corliss (corliss@digitalmages.com)

LICENSE AND COPYRIGHT ^

This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information.

(c) 2005, Arthur Corliss (corliss@digitalmages.com)

syntax highlighting: