How to find out if another process is using a file
Donn Cave
donn at u.washington.edu
Thu Jan 18 17:26:35 EST 2007
In article <eookeb$1ar$1 at gemini.csx.cam.ac.uk>,
nmm1 at cus.cam.ac.uk (Nick Maclaren) wrote:
> In article <donn-66A101.12021118012007 at gnus01.u.washington.edu>,
> Donn Cave <donn at u.washington.edu> writes:
> |> In article <mailman.2878.1169141728.32031.python-list at python.org>,
> |> "Gabriel Genellina" <gagsl-py at yahoo.com.ar> wrote:
> |> > "Tom Wright" <tew24 at spam.ac.uk> escribió en el mensaje
> |> > news:eoo6vd$33u$1 at gemini.csx.cam.ac.uk...
> |> > Use os.open with the O_EXCL flag; will fail if the other process has the
> |> > file still open (and will fail if another process is reading the file,
> |> > too,
> |> > not just if someone is writing).
> |>
> |> 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.
Donn
More information about the Python-list
mailing list