On Sat, Nov 27, 2004 at 07:22:06PM +0800, John Summerfield wrote: > On Saturday 27 November 2004 10:34, Doug Stewart wrote: > > It might be a better idea to simply write out a "lockfile" and check for > > its presence before running. > > You still need to e wary of race conditions; that is why I counsel locking the > file. > What I've done in C programs is to create the lock file and put my PID in it. Whenever the program starts, if the lock file is not present it's safe to start (assumed). If it's present, open it and read the PID value. Look up the PID to see if it still exists. If it does, assume it is the correct process (which it may not since PIDs do get recycled in time) and abort the program. If the file exists and the PID doesn't, the program probably died without cleaning up, so just delete the lock file then create a new one with your own PID. During the process of creating the file, you need to lock it to avoid race conditions. In C I'd use fcntl or lockf or some such. I don't know what you'd do in PERL but there surely is a mechanism. -- ---- Fred Smith -- fredex@xxxxxxxxxxxxxxxxxxxxxx ----------------------------- "For the word of God is living and active. Sharper than any double-edged sword, it penetrates even to dividing soul and spirit, joints and marrow; it judges the thoughts and attitudes of the heart." ---------------------------- Hebrews 4:12 (niv) ------------------------------
Attachment:
pgpsCdvMZaFCg.pgp
Description: PGP signature