[CVS] pidfile support
rjs3 at andrew.cmu.edu
Tue Dec 17 10:26:13 EST 2002
On Tue, 17 Dec 2002, Henrique de Moraes Holschuh wrote:
> It won't. We will have to transfer the lock to B without a
> race-condition. That means IPC, or signals, or something like that...
Yeah, I was discussing this with someone in the office yesterday, and
there's a half-decent way to do this, but it does requrie signals (well, a
pipe), and two locks.
> One other possile way to do it, is to use the _presence_ of the pidfile with
> a running process with that pid (specified in the pidfile) as the lock. We
> remove the file on exit (clean or otherwise), and we ignore it at startup if
> there is no such a process running in the system.
I'm not sure I like using the presence of the pidfile, and this method
feels a bit kudgy to me (using kill to detect the presence of the process,
for example). Like you mention, there's also a minor race. I think we
can do better:
[A] Create/lock pidfile.lock. If locked, exit(failure).
[A] Create a pipe
[A] Fork [B]
[A] Block on reading exit code from pipe
[B] Create/lock pidfile If locked, write failure code to pipe and exit(failure)
[B] write pid to pidfile
[B] write success code to pipe & finish starting up
[A] exit(code read from pipe)
I think this works no matter how the things are interleaved after forking.
Rob Siemborski * Andrew Systems Group * Cyert Hall 207 * 412-268-7456
Research Systems Programmer * /usr/contributed Gatekeeper
More information about the Info-cyrus