Name
flock
Synopsis
flock filehandle, operation
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
flockfrom blocking while trying to establish a lock withLOCK_SHorLOCK_EXand instructs it to return immediately.LOCK_NBmust be ored with the other operation as an expression for the operation argument, i.e.,(LOCK_EX |LOCK_NB).