File::Flock(3pm)

File::Flock3pm

Usage

 use File::Flock;
 lock($filename);
 lock($filename, 'shared');
 lock($filename, undef, 'nonblocking');
 lock($filename, 'shared', 'nonblocking');
 unlock($filename);
 lock_rename($oldfilename, $newfilename)
 my $lock = new File::Flock '/somefile';
 $lock->unlock();
 $lock->lock_rename('/new/file');
 forget_locks();

Overview

Lock files using the flock() call. If the file to be locked does not exist, then the file is created. If the file was created then it will be removed when it is unlocked assuming it's still an empty file.

Locks can be created by new'ing a File::Flock object. Such locks are automatically removed when the object goes out of scope. The unlock() method may also be used.

lock_rename() is used to tell File::Flock when a file has been renamed (and thus the internal locking data that is stored based on the filename should be moved to a new name). unlock() the new name rather than the original name.

Locks are released on process exit when the process that created the lock exits. Subprocesses that exit do not remove locks. Use forget_locks() or POSIX::_exit() to prevent unlocking on process exit.

Packagers

File::Flock is packaged for Fedora by Emmanuel Seyman <[email protected]>.

Releases

6 releases since Debian 7 (Wheezy); the text changed 3 times.

  1. 7
  2. 9–10
  3. 11
  4. 12–13

License

Copyright (C) 1996-2012 David Muir Sharnoff <[email protected]> Copyright (C) 2013 Google, Inc. This module may be used/copied/etc on the same terms as Perl itself.

From libfile-flock-perl 2014.01-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.