Determining if an existant file is open

Jon Nadelberg aeusejvn at csunb.csun.edu
Fri Nov 16 13:31:10 AEST 1990


We have a program that while running maintains a checkpoint file.  This
file is named based on the users id, and is stored in a specific directory
on the system.  

Our problem occurs when someone tries to start up another process under
the same user id while the first one is running. 

The first concern is that the second process, upon seeing the existence
of the checkpoint file created by the first process think that it needs
to "warmstart" from the first file.  It should not do this.  Second,
once the new process does this, it then re-initializes the checkpoint
file thus corrupting it.  

Our thinking is this: if we can determine whether or not the checkpoint
file is currently open by the first process, we can then make the decision
as to whether or not to continue with a warmstart process, or in the
case of the file still being open, not starting up a checkpoint file
for subsequent processes.
 
Is there a way to check if a file is currently open and being used by
another process?  Is there a way to "lock" a file so that other processes
can not access it?  
 
We are kind of stuck with the implementation staying the way it is.  The only
thing we can do is Band-Aid it, so a redesign of the way it works is
not a practical suggestion at this point.
 
Any help would be appreciated.  
Thank you.

--
------------------------------------------------------------------------
-   Jon Nadelberg                                                      -
-   aeusejvn at csunb.csun.edu                                            -
------------------------------------------------------------------------



More information about the Comp.unix.programmer mailing list