Perl flock Function
This function supports file locking on the specified FILEHANDLE using the system flock( ), fcntl( ) locking, or lockf( ). The exact implementation used is dependent on what your system supports. OPERATION is one of the static values defined here.
Operation Result LOCK_SH Set shared lock. LOCK_EX Set exclusive lock. LOCK_UN Unlock specified file. LONG_NB Set lock without blocking.
Following is the simple syntax for this function −
flock FILEHANDLE, OPERATION
This function returns 0 on failure to set/unset lock and 1 on success to set/unset lock.
Following is the example code showing its basic usage −
When above code is executed, it produces the following result −