lockfile type locks

Leslie Mikesell les at chinet.chi.il.us
Fri Jul 6 00:54:51 AEST 1990


Looking at the code for a mailer that uses lockfiles (/usr/mail/logname.lock)
to obtain exclusive access to the mail file I've become convinced that
there is *no* robust way to detect and delete lockfiles that have been
accidentally left in place.  The popular method of picking up the PID
from the lockfile and sending signal 0 to the locking process will often
falsely indicate that the file is stale since the process that owned the
previous lockfile may exit between the time the checking process reads
the PID and issues the signal.  Worse, regardless of the method of
determination, there is no way to insure that the file removed by
unlink() is the same file that was checked.  Another similar process
may have just gone through the same procedure and created its lockfile
between this process's check and unlink().

Am I missing something?

Les Mikesell
  les at chinet.chi.il.us



More information about the Comp.unix.questions mailing list