Next | File Locking | 7 |
flock FH, LOCK_EX; # modify the data
Serious problem here
If the lock is unavailable, this waits until it is available
If the lock is available, this gets the lock and continues immediately
But what if the system call fails for some reason?
For example, if FH is not open?
Then it returns immediately
The process then modifies the data
Even though it does not have the lock!
Always check for failure!
flock FH, LOCK_EX or die ...;
if (flock FH, LOCK_EX) { # modify the file ... }
Next | Copyright © 2003 M. J. Dominus |