Name
flock
Synopsis
flock filehandle, operation
Description
Establishes or removes a lock on a file opened with filehandle.
This function calls one of the Unix functions flock
, lockf
, or the
locking capabilities of fcntl
, whichever your system supports. If
none of these functions exist on your system, flock
will produce
a fatal error.
operation is the type of locking function to perform.
The number by each operation name is the argument that Perl’s flock
takes by default. You may also use the operation names if you explicitly
import them from the Fcntl module with use Fcntl ":flock"
.
-
LOCK_SH
(1) Establishes a shared lock on the file (read lock).
-
LOCK_EX
(2) Establishes an exclusive lock on the file (write lock).
-
LOCK_UN
(8) Removes a lock from the file.
-
LOCK_NB
(4) Prevents
flock
from blocking while trying to establish a lock withLOCK_SH
orLOCK_EX
and instructs it to return immediately.LOCK_NB
must be ored with the other operation as an expression for the operation argument, i.e.,(LOCK_EX | LOCK_NB)
.
Get Perl in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.