Ljubisa Gavrilovic (Traserman International Ltd) wrote:

> Just one small question... Do I need to flock() even if it is O_EXCL ?

The O_EXCL flag to open() means that open() will fail if the file
already exists (although it isn't reliable over NFS).

Whether or not you still need to use locking depends upon how the file
is accessed. If a file will only ever be opened for writing with the
O_EXCL flag set, then the file wouldn't normally be open for more than
one process (although this can happen if a process creates the file
and then fork()s).

You still need to use flock() if you need to prevent one process from
reading to a file whilst another process is writing to it, or if you
need to prevent multiple related processes from accessing a file which
one of them has inherited from its parent.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to