synchronizing concurrent shell scripts

Michael L Torrie torriem at chem.byu.edu
Mon Feb 12 13:06:59 MST 2007


On Mon, 2007-02-12 at 12:04 -0800, Michael Brailsford wrote:
> bash-2.03$ sudo find /usr -name lockfile
> bash-2.03$ uname -a
> AIX <snip> 3 5 00C5227E4C00
> 
> Not so standard, methinks.  AIX 5.3L has no such command.

I'll rephrase that.  Any modern unix should have this command. :)
Unless you happen to be using some old archaic unix.

> 
> However, touch works well.  Something like this has always worked for me.
> 
> 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?


Michael

> 
> 
> 
> 
> ----- Original Message ----
> From: Bart Whiteley <bart.plug at whiteley.org>
> To: Provo Linux Users Group Mailing List <plug at plug.org>
> Sent: Monday, February 12, 2007 1:03:19 PM
> Subject: Re: synchronizing concurrent shell scripts
> 
> On 2/12/07, Michael L Torrie <torriem at chem.byu.edu> wrote:
> >
> > On Mon, 2007-02-12 at 11:45 -0700, Michael L Torrie wrote:
> > > I have a situation where shell scripts, executed asynchronously, need to
> > > have a way to wait for each other when doing a load-intensive operation.
> > > Do any of you have any methods for synchronizing the operation of
> > > concurrent shell scripts?
> >
> > My bad.  Google reveals that there's a nice standard unix
> > command: /usr/bin/lockfile
> >
> > man lockfile reveals this is just what I'm looking for.
> >
> >
> lockfile... cool.  If you happen to be using bash, you can do the same thing
> with a 'set -o noclobber' and avoid the overhead of forking an additional
> process (lockfile).
> http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_06.html#sect_03_06_02
> 
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
> 
> 
> 
> 
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
> 




More information about the PLUG mailing list