lpadmin(8) question

Stu Donaldson stu at gtisqr.uucp
Thu Jun 7 06:03:18 AEST 1990


In article <162 at twg.bc.ca> bill at .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 at twg.bc.ca      (604) 431-4629 (fax)   |     Integration
-- 
Stu Donaldson          UUCP: {smart-host}!gtisqr!stu
Engineering Manager    ARPA: gtisqr!stu at yang.cpac.washington.edu
Global Technology      Bell: (206) 742-9111
Mukilteo, Washington.



More information about the Comp.unix.i386 mailing list