synchronizing concurrent shell scripts
bart.plug at whiteley.org
Mon Feb 12 13:20:03 MST 2007
On 2/12/07, Michael L Torrie <torriem at chem.byu.edu> wrote:
> > However, touch works well. Something like this has always worked for
> > while [ -d /var/somelockfile ]; do sleep 1; done
> > touch /var/somelockfile
> > # do something
> > rm /var/somelockfile
> Sadly this will not work, at least if you goal is to synchronize
> multiple scripts running asynchronously. It would have worked in my
> case, but it's not a semaphore. Who wins when several processes make it
> past the while loop at about the same time?
Right. This is why you should use the redirect '>' with noclobber instead.
With noclobber, the redirect works like an atomic test-and-set.
More information about the PLUG