Reference: flock (Perl in a Nutshell)

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: filenoChapter 5
Function Reference
Next: Reference: fork
 

flock

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 flock from blocking while trying to establish a lock with LOCK_SH or LOCK_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).


Previous: Reference: filenoPerl in a NutshellNext: Reference: fork
Reference: filenoBook IndexReference: fork

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.