Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: single instance Date: Sat, 5 Jan 2013 20:29:52 +0000 (UTC) Organization: UK Free Software Network Lines: 34 Message-ID: References: NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1357417792 17291 84.45.235.129 (5 Jan 2013 20:29:52 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Sat, 5 Jan 2013 20:29:52 +0000 (UTC) User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.java.programmer:20997 On Sat, 05 Jan 2013 13:02:57 -0500, Twirlip of the Mists wrote: > C's atexit is probably vulnerable to the latter two, mitigatable only > partially by registering signal handlers. > I don't think any of these approaches are immune to system crashes, but should be good enough to prevent single processes, whether launched by a user or automatically by the system, from running more copies that are wanted. I'd normally use a shell script or programmed equivalent to launch a more complex set of processes. Its first action would be to assume a crash had ocurred and do a full clean-up: if the system had shut down normally the clean-up would still run but would not find anything to do. > The only thing I can think of that even the thunderstorm won't fuck up > is an active system where the lockfile is only considered valid if some > associated "heartbeat" is still going, so, the lockfile invalidates on a > deadman switch even if not deleted. > Yes, that would work too: though it sounds as if the mere existence of a small 'heartbeat' process could obviate the need for a lockfile: if the heartbeat process is running and agrees that the limit for your process type hasn't been reached, your process can start. In all other circumstances it can't start. As a bonus, if all processes periodically checked the heartbeat process state and exited of the heartbeat said 'die', it could also be used as a convenient way to shut a complex system down. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |