robust locking
Rahul Dhesi
dhesi%cirrusl at oliveb.ATC.olivetti.com
Wed Aug 29 04:40:05 AEST 1990
Here is a suggestion about locking mechanisms.
Both rn and nn assume that a user's home directory is available only on
one host. This is not necessarily true if you have NFS. It has
occasionally happened to me with rn that I had an rn session going on
one host and started another on a different host on which I had the
same NFS-mounted directory. The second rn, not finding the first rn's
process, assumed it had crashed.
I think nn, too, does not attempt to ensure that no nn is active for
the same user on any host.
A very simple mechanism can be used to ensure that such race conditions
don't occur. Create a lock file that contains both process id and host
name. If a second process wants to create the same lock, it checks any
existing lock file. If the lock file exists, and the host name in it
is that of the current host, then the process id in it can be tested to
see if it is that of an existing process (and if not, that process
crashed and the lock file can be superseded). But if the host name in
the lock file is that of a different host, we refuse to supersede the
lock.
I recommend this locking scheme in place of the usual pid-only lock
file for all software, not just rn and nn.
--
Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP: oliveb!cirrusl!dhesi
More information about the Comp.unix.questions
mailing list