How can a process tell if another process has a file open?

How can a process tell if another process has a file open?

Post by Tru » Wed, 03 Nov 1993 23:36:54



Is there a way to tell if another process has a file open? I'm running two
processes which open the same file (call them process A and process B).
Process A creates the file, writes to it, and closes it. Process B is
monitoring the directory where process A will be creating files. When it
detects a file, it will open it, read and process it, close it, and remove
the file.

My problem is that I have no control over process A. This process is
developed by another organization here at NCR. I can only control
process B. Is there any way that process B can detect if process A (or
any other process) has the file open?

 
 
 

How can a process tell if another process has a file open?

Post by Rob Dori » Thu, 04 Nov 1993 14:52:24


True> Is there a way to tell if another process has a file open? I'm
True> running two processes which open the same file (call them
True> process A and process B).  Process A creates the file, writes to
True> it, and closes it. Process B is monitoring the directory where
True> process A will be creating files. When it detects a file, it
True> will open it, read and process it, close it, and remove the
True> file.

True> My problem is that I have no control over process A. This
True> process is developed by another organization here at NCR. I can
True> only control process B. Is there any way that process B can
True> detect if process A (or any other process) has the file open?

Just make sure that you do open(...., BLKANDSET|..., ...) (or use
flock()), from both processes, so you will have mutual exclusion.
Process A will still have to monitor the directory in order to only
open the file once it has been created by B; of course B could do
something like this:

while (open("file", ...|RD_ONLY|BLKANDSET, ...)<0);

Good luck,

Roberto
--




----------------------------------------------------------------------------

 
 
 

How can a process tell if another process has a file open?

Post by Henry J. Co » Fri, 19 Nov 1993 23:47:24


<Is there a way to tell if another process has a file open? I'm running two
<processes which open the same file (call them process A and process B).
<Process A creates the file, writes to it, and closes it. Process B is
<monitoring the directory where process A will be creating files. When it
<detects a file, it will open it, read and process it, close it, and remove
<the file.
<
<My problem is that I have no control over process A. This process is
<developed by another organization here at NCR. I can only control
<process B. Is there any way that process B can detect if process A (or
<any other process) has the file open?

        Spin on the directory's modification time.

        The better answer is to make the file a FIFO (mkfifo()) and block
for input.  (or select(), if you have better things to do.)

        BTW: anybody know how to finger the holder of a lockf()?
--

        "Ignorance is strength." -Orwell knew modular design.