From owner-freebsd-questions Sat Apr 25 11:42:48 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA27869 for freebsd-questions-outgoing; Sat, 25 Apr 1998 11:42:48 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from caladan.tdx.co.uk (caladan.tdx.co.uk [195.188.177.4]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA27853 for ; Sat, 25 Apr 1998 11:42:32 -0700 (PDT) (envelope-from kpielorz@tdx.co.uk) Received: from tdx.co.uk (lorca-tx.tdx.co.uk [195.188.177.242]) by caladan.tdx.co.uk (8.8.8/8.8.8) with ESMTP id TAA23293 for ; Sat, 25 Apr 1998 19:42:30 +0100 (BST) (envelope-from kpielorz@tdx.co.uk) Message-ID: <35422E96.AFE7E766@tdx.co.uk> Date: Sat, 25 Apr 1998 19:42:30 +0100 From: Karl Pielorz Organization: TDX X-Mailer: Mozilla 4.04 [en] (WinNT; I) MIME-Version: 1.0 To: questions@FreeBSD.ORG Subject: Protecting Shell scripts from deadlocks... Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, I have a small(ish) script which runs on my system quite often... The system is fairly fast - but I need to make sure that the script isn't run again whilst there is another copy running... Thus far I do this: ------ if [ -f "/var/run/visitor.lock" ] then echo "Allready running." exit fi # No one running, so we can set the lock file... touch /var/run/visitor.lock # Rest of script... # Clear the lock... rm /var/run/visitor.lock ------ As part of rc.local - I check for - and remove the lock in case the script was running when the system went down... There must be a better way of doing this in scripts? - Theres always the chance another instance might start between me checking the lock file - and creating the lock file... If there is no better way of doing this - I don't mind converting the whole script to 'C' - in which case I presum 'man flock' is a good place to start? Regards, Karl Pielorz To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message