From: Christopher Brown Date: 2006-08-14T14:06:12+09:00 Subject: Re: How do you use flock and clean up lock files? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ah, gotcha. You really don't need strong cross-process synch, but just proof another of your processes already exists. It sounds like you are following most of the guidance from APUE. In which case, on *nixes, why not write a pidfile in /var/run? It's a fairly standard way to do things. Write the process id into /var/run/.pid. Any launch of the daemon should check for the existence of this file first and for added hygiene, check the actual process id written into it against what's in the process table (or against /proc/ if on Linux). At the end of the day, it's much like the lockfile version, but gives a bit more information and some tools will work directly with the pidfile. On some Linux distros, there are tools that will create it for you and take the daemon managment out of your hands if you choose. The Windows process model is quite a bit different, and really favors creating new threads (I guess not what you want here...) Fork / exec model isn't directly supported. I guess some toolkits attempt to fake it though. There's a nifty description of the cygwin implementation here: http://www.cygwin.com/cygwin-ug-net/highlights.html I guess this is drifting off-topic from Ruby, so I'll shut up now. Peace, Chris On 14 Aug 2006, at 6:49 AM, John Carter wrote: > > On Mon, 14 Aug 2006, Christopher Brown wrote: > >> John are you using flock because it's the easiest & most available >> way to sync across processes? If you had easier access to one of >> the other sync primitives, would you be using it (i.e. a mutex)? >> I'm just wondering what the dominant pattern is, and if we are >> using it because something better hasn't come along. > > > I'm have a generic Daemon class exactly like Process.fork but > Daemon.spawn does things like... > > * Check, via a lock file, that another copy of itself isn't running > somewhere. > > * Has a method to kill all copies of itself (via fuser) > > * Detaches itself from the controlling terminal (making it self a true > Daemon) so it doesn't die if parent process dies. > > * Can wait until the dameon has started, can wait for it to die. > > I suspect I could use fcntl and mandatory locking, but I'm not sure > that > would help with this problem. > > Ps: (What do Windowsy types do instead of "Process.fork"? ) > > > John Carter Phone : (64)(3) 358 6639 > Tait Electronics Fax : (64)(3) 359 4632 > PO Box 1645 Christchurch Email : john.carter@tait.co.nz > New Zealand > > Carter's Clarification of Murphy's Law. > > "Things only ever go right so that they may go more spectacularly > wrong later." > > From this principle, all of life and physics may be deduced. > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (Darwin) iD8DBQFE4ASnrOGxDZoCCzURAv7mAKDHcRZksMTCJDij3D+CayD41sn1ggCfWgVS RnT7l0wjPDKKUoBHSAjl+nM= =u++g -----END PGP SIGNATURE-----