|Don't ask to ask, just ask
Re: Preventing multiple instances (References on flock and running one copy of a script at a time)by eyepopslikeamosquito (Archbishop)
|on Dec 17, 2020 at 08:32 UTC
Here's some sample code, using Perl's flock function, that I've used for many years on both Unix and Windows, to ensure only one copy of a script is running at a time (update: run on local file systems only, not NFS).
You can easily test its behaviour by running the little test program above in two different terminal sessions (and either waiting for the sleep to end or manually killing one of the processes).
from his classic poem my @chickens (by the way, pjf is one of the few monks I've met in real life; in addition to running chickens in his backyard, he has a keen interest in picking and eating unusual and delicious wild plants you won't find in any supermarket ... not for the faint-hearted, you need a keen eye and expert knowledge to avoid being poisoned).
References Added Later