How many users of a file?

Prolly a stupid basic UNIX programming question, but how do I tell
how many programs have a file open?

Basically, I need to know if a file is in use or not before I destructively
modify it.

Cheers,
-RK


[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/

Not POSIX, but QNX have a iofdinfo().

-xtang

Robert Krten <rk@parse.com> wrote in message
news:bv4flv$ffr$1@inn.qnx.com

Prolly a stupid basic UNIX programming question, but how do I tell
how many programs have a file open?

Basically, I need to know if a file is in use or not before I
destructively
modify it.

Cheers,
-RK


[If replying via email, you’ll need to click on the URL that’s emailed to
you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector > http://www.parse.com/~pdp8/

Robert Krten <rk@parse.com> wrote:

Prolly a stupid basic UNIX programming question, but how do I tell
how many programs have a file open?

No POSIX way.

Basically, I need to know if a file is in use or not before I destructively
modify it.

unlink() the file.
open( O_CREAT) the same file.

Existing opens will keep a copy of the old file – you’ll get a new one.

-David

Cheers,
-RK


[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector > http://www.parse.com/~pdp8/


David Gibbs
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote:

Robert Krten <> rk@parse.com> > wrote:
Prolly a stupid basic UNIX programming question, but how do I tell
how many programs have a file open?

No POSIX way.

Basically, I need to know if a file is in use or not before I destructively
modify it.

unlink() the file.
open( O_CREAT) the same file.

Existing opens will keep a copy of the old file – you’ll get a new one.

Thanks, Dave, but xtang’s suggestion is what I’m using now, because I
need to not unlink the file if it’s in use :slight_smile:

Cheers,
-RK


-David

David Gibbs
dagibbs@qnx.com


[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/