Reading the journal of brain d foy I noticed his filecounter entry where talks about using O_EXCL instead of flock. However I was under the impression O_EXCL is related to O_CREAT when the file exists, and should be used when you use rename() to get atomic operation at the filesystem level. In fact quoted fom perldoc -f open is the following.
In many systems the "O_EXCL" flag is available for
opening files in exclusive mode. This is not
locking: exclusiveness means here that if the file
already exists, sysopen() fails. The "O_EXCL"
wins "O_TRUNC".
You're right: O_EXCL only matters with O_CREAT. It guarantees (on a local filesystem, at least, don't expect anything on networked filesystems) that the open(2) fails (with errno == EEXIST) if a file by the specified name already exists. Nothing to do with locking, only to do with EXCLusive CREATion.
flock != O_EXCL (Score:2)
No, its me. (Score:1)
Thanks