How to find out if another process is using a file
nmm1 at cus.cam.ac.uk
Thu Jan 18 23:43:26 CET 2007
In article <donn-DA887B.14263518012007 at gnus01.u.washington.edu>,
Donn Cave <donn at u.washington.edu> writes:
|> > |>
|> > |> O_EXCL fails if the file exists at all - whether closed or open.
|> > Yes. In theory. In practice, it usually works on normal files, provided
|> > that all opens are local. Under some circumstances, it will even work
|> > for NFS mounted files, as far as I recall.
|> Mm, by "fail", I meant
|> An attempt to open with O_EXCL set will "fail" if the file exists at all,
|> i.e., the file will not be opened, a negative value will be returned,
|> and errno will be set to EEXIST.
|> What I neglected to mention is that this effect obtains when O_EXCL
|> is used in combination with O_CREAT. Without O_CREAT, O_EXCL doesn't
|> mean anything and is ignored.
|> If there is any significant difference between theory and practice
|> in this matter, it's news to me.
Actually, it is undefined behaviour in POSIX, and I have used a Unix
where O_EXCL on its own failed if the file existed (of course, it also
failed if it DIDN'T exist, because of the lack of O_CREAT). I can't
remember which - perhaps AIX or OSF/1 (not DEC).
But I was referring to a different problem. Some remote and parallel
filing systems handle such things very badly, and it is often possible
to create a file even if it exists and O_CREAT|O_EXCL is set. A similar
remark applies to 'special' files, even on fairly mainstream, local
More information about the Python-list