Next | File Locking | 2 |
Like a traffic light for processes
Only one street has a green light at any time
Only one process has a file lock at any time
use Fcntl ':flock';
Wait until lock is available and then get the lock:
flock(FILEHANDLE, LOCK_EX) or die ...;
Try to get lock, return immediately:
if (flock(FILEHANDLE, LOCK_EX | LOCK_NB)) { # I have the lock } else { # I don't }
Release lock:
flock(FILEHANDLE, LOCK_UN);
Next | Copyright © 2003 M. J. Dominus |