Also sprach Purl Gurl:
Rene Scheibe wrote:
(snipped)
If you are a talented programmer, you know of your machine's
file locking numbers. If not, you may use the Fcntl module
designed for the less talented. Neither method is a guarantee
of file locking but both are relatively reliable.
Neither method? I only see one method here, namely through flock().
And, well, I don't understand this part about reliability either. If the
call to flock(2) was successful, it's pretty safe to assume that the
file is now locked. However, depending on the platform a lock may be
advisory in which case any process may just as easily ignore it. But any
process that itself tries to acquire a flock on a locked file will be
blocked until the initial flock is released.
And, eventually, there are those platforms that don't even have a
flock() system-call, such as Win95/98/ME.
You should not experience any problems for typical usages. Fcntl will
provide better portability.
Indeed. And yet, it's only a fraction of what should be done. Locking of
files can become a real nuisance when different platforms are taken into
account. Often you end up implementing various mechanisms (flock()
versus dot-file locking via sysopen()) to satisfy most machines.
Tassilo