Determining if an existant file is open

0257014-Robert White140 rwhite at nusdecs.uucp
Sat Nov 17 07:09:45 AEST 1990


In article <1990Nov16.023110.1305 at csun.edu> aeusejvn at csunb.csun.edu (Jon Nadelberg) writes:
>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?  

The things that come immedately to mind are:

Use the exclusive flag when calling open(2) -- must be done every time.

Allow multiple opens and have the processes do read and write locks
as approprate, being shure to always lock before read (you shouldn't
need manditory locks in this case, just be consistant).  If the file
is locked the file is busy.  fnctl(2) or ioctl(2) I dont remember
which right now.

Do the "put process number in lock file" thing as in uucp.

Any sutble differences between these thecniques should be considered
based on the exact internals of the app.  And then combine as many of
these as is reasonable.

Hope it was some help,
Rob.



More information about the Comp.unix.programmer mailing list