At most 1 running copy

fredex fredex at fcshome.stoneham.ma.us
Sat Nov 27 14:46:11 UTC 2004


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 at fcshome.stoneham.ma.us -----------------------------
   "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) ------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20041127/5ce57d9d/attachment-0001.sig>


More information about the fedora-list mailing list