How to find out if another process is using a file

Donn Cave donn at
Thu Jan 18 23:26:35 CET 2007

In article <eookeb$1ar$1 at>,
 nmm1 at (Nick Maclaren) wrote:
> In article <donn-66A101.12021118012007 at>,
> Donn Cave <donn at> writes:
> |> In article <mailman.2878.1169141728.32031.python-list at>,
> |>  "Gabriel Genellina" <gagsl-py at> wrote:
> |> > "Tom Wright" <tew24 at> escribió en el mensaje 
> |> > news:eoo6vd$33u$1 at

> |> > Use 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.


More information about the Python-list mailing list