Date: Sat, 25 Apr 1998 19:42:30 +0100 From: Karl Pielorz <kpielorz@tdx.co.uk> To: questions@FreeBSD.ORG Subject: Protecting Shell scripts from deadlocks... Message-ID: <35422E96.AFE7E766@tdx.co.uk>
next in thread | raw e-mail | index | archive | help
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... <snip> # 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35422E96.AFE7E766>