PerlIO::flock - Easy flock() interface


PerlIO-Util documentation  | view source Contained in the PerlIO-Util distribution.

Index


NAME

Top

PerlIO::flock - Easy flock() interface

SYNOPSIS

Top

	open my $in,  '< :flock', $file; # shared lock
	open my $out, '+<:flock', $file; # exclusive lock

	binmode($fh, ':flock(blocking)');
	binmode($fh, ':flock(non-blocking)');

DESCRIPTION

Top

PerlIO::flock provides an interface to flock().

It tries to lock the filehandle with flock() according to the open mode. That is, if a file is opened for writing, :flock attempts exclusive lock (using LOCK_EX). Otherwise, it attempts shared lock (using LOCK_SH).

It waits until the lock is granted. If an argument non-blocking (or LOCK_NB) is supplied, the call of open() (or binmode()) fails when the lock cannot be granted.

This is a pseudo layer that doesn't be pushed on the layer stack.

EXAMPLE

Top

	# tries shared lock, or waits until the lock is granted
	open my $in, "<:flock", $file;
	open my $in, "<:flock(blocking)", $file;     # ditto.

	# tries shared lock, or returns undef
	open my $in, "<:flock(non-blocking)", $file; 
	open my $in, "<:flock(LOCK_NB)", $file;      # ditto.

SEE ALSO

Top

PerlIO::Util.

flock in perlfunc.

AUTHOR

Top

Goro Fuji (藤 吾郎) <gfuji (at) cpan.org>

LICENSE AND COPYRIGHT

Top


PerlIO-Util documentation  | view source Contained in the PerlIO-Util distribution.