Start by understanding http://en.wikipedia.org/wiki/File_locking.
(Consider rewriting the code to use three-argument open and variables instead of barewords as file handles.)
What really happens is that you voluntarily protect the code between flock S and close S. flock S will block (not return) until no other process has a lock on the semaphore file. The data file is not locked at all, and as long as all processes accessing the data file agree to lock the semaphore file instead, it does not have to be locked. Locking the semaphore file guarantees that only one process per machine can access the file.
Alexander
In reply to Re: Trying to understand flock
by afoken
in thread Trying to understand flock
by toniax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |