Determining if an existant file is open

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Thu Nov 22 06:42:10 AEST 1990


In article <274975C4.21C at tct.uucp> chip at tct.uucp (Chip Salzenberg) writes:
> According to rwhite at nusdecs.uucp (0257014-Robert White(140)):
> >Do the "put process number in lock file" thing as in uucp.
> This approach cannot be used reliably without either (1) having a lock
> held forever by a dead process, which I find unacceptable, or (2)
> using a kernel locking call, which renders the pid file redundant.

It can be used reliably if you put information like pid and date into
the name of the lock file.

> For you doubters: Once you've determined that a lock file is stale and
> you want to unlink() it, how do you know the lock file hasn't been
> replaced in between the decision to unlink() and the unlink() itself?

The old name will never be reused, so there's no danger of replacement.

---Dan



More information about the Comp.unix.programmer mailing list