Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!mit-eddie!uw-beaver!fluke!gtisqr!stu From: stu@gtisqr.uucp (Stu Donaldson) Newsgroups: comp.unix.i386 Subject: Re: lpadmin(8) question Summary: safer form of lock. Keywords: lp systemv Message-ID: <1990Jun6.200318.1619@gtisqr.uucp> Date: 6 Jun 90 20:03:18 GMT References: <453@van-bc.UUCP> <162@twg.bc.ca> Reply-To: stu@gtisqr.UUCP (Stu Donaldson) Organization: Global Tech Int'l Inc. Lines: 53 In article <162@twg.bc.ca> bill@.UUCP (Bill Irwin) writes: ># >if [ -f /tmp/computer.lock ] >then > while [ -f /tmp/computer.lock ] > do > sleep 60 > done >fi >touch /tmp/computer.lock ... model/interface stuff deleted ... >rm /tmp/computer.lock >The only drawback with this approach that I have encountered is when you >cancel a print job the lock is not removed. You have to remember to "rm >/tmp/computer.lock" after your cancel, otherwise you next jobs will never >print. A safer solution that I have used for locks, that solvs the problem of the lock file being left around is: while [ -f /tmp/computer.lock ] do if ps -p`cat /tmp/computer.lock` >/dev/null 2>&1 then sleep 60 else rm -f /tmp/computer.lock # lock invalid, so remove. fi fi echo $$ >/tmp/computer.lock # I should lock it. # for added security, the following test can be made. sleep 2 if [ "$$" != "`cat /tmp/computer.lock`" ] then ... lock failed, go back and try again? ... fi >-- >Bill Irwin - TWG The Westrheim Group - Vancouver, BC, Canada >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >uunet!van-bc!twg!bill (604) 431-9600 (voice) | UNIX Systems >Bill.Irwin@twg.bc.ca (604) 431-4629 (fax) | Integration -- Stu Donaldson UUCP: {smart-host}!gtisqr!stu Engineering Manager ARPA: gtisqr!stu@yang.cpac.washington.edu Global Technology Bell: (206) 742-9111 Mukilteo, Washington.