Path: utzoo!attcan!uunet!timbuk!cs.umn.edu!msi-s0.msi.umn.edu!srcsip!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!ucdavis!uop!quack!mrapple From: mrapple@quack.sac.ca.us (Nick Sayer) Newsgroups: comp.unix.questions Subject: Does this lockfile method work? Message-ID: Date: 27 Sep 90 17:36:10 GMT Organization: The Duck Pond, Stockton, CA Lines: 31 void get_lock() { sprintf(tmpname,"/tmp/t_%d",getpid()); fp=fopen(tmpname,"w"); fprintf(fp,"%d\n",getpid()); fclose(fp); while(link(tmpname,"/tmp/LOCK")!=0) sleep(30); unlink(tmpname); } void release_lock() { unlink("/tmp/LOCK"); } Presuming for the moment that the possibility of an infinite wait within the while loop won't occur, and release_lock() won't be called unless the lock was previously aquired by this process, does anyone see any exclusivity problems with this code? In particular, is there any conceivable circumstance where the link() function fails when multiple processes are trying to link into the same destination? In this context, "fails" means anything other than one process completing the link() successfully and all the others getting EEXISTS. -- Nick Sayer | Disclaimer: N6QQQ [44.2.1.17 soon] | "Just because you're reading my post doesn't mrapple@quack.sac.ca.us | mean we're gonna take long showers together." 209-952-5347 (Telebit) | -- Gunnery Sgt. Thomas Highway