zsh-users
 help / color / mirror / code / Atom feed
From: Anthony R Fletcher <arif@mail.nih.gov>
To: <zsh-users@zsh.org>
Subject: Re: wait for the next process to finish
Date: Tue, 13 Dec 2011 12:32:37 -0500	[thread overview]
Message-ID: <20111213173237.GA10838@cosy.cit.nih.gov> (raw)
In-Reply-To: <alpine.DEB.2.00.1112131023060.13348@MyComp.localdomain>


On 13 Dec 2011 at 11:04:44, Rory Mulvaney wrote:
> pids=( )
> R=( $RANDOM $RANDOM )
> echo $R
> coproc () { sleep $(( $R[1]/32767.0*20 )) ; echo $$ }
> pids+=$!
> # copy the coproc fd
> exec 3<&p
> coproc () { sleep $(( $R[2]/32767.0*20 )) ; echo $$ }
> pids+=$!  
> exec 4<&p
> zmodload zsh/zselect
> zselect -r 3 4
> echo $reply
> 
> Then one could parse $reply.
> 
> I don't know, maybe there's a much easier way to create file descriptors 
> for those processes?
> 
> -Rory

I was using this loop

  for f in *.txt
  do
	  what-ever-has-to-happen $f &
	  pwait 20
  done

where pwait is a function

  function pwait() {
          while [ $(jobs -rp | wc -l) -ge $1 ]
          do
		  # sleep 10
                  wait
          done
  }

(see http://superuser.com/questions/158165/parallel-shell-loops for one
example amongst many).

I was hoping that using "wait" would be better than using a "sleep 10".
But wait waits for them all and not just he last to finish. The nice
thing is that this is a small, easy loop and all the brains is in the
barrier function pwait. Sadly a sleep for 10 seconds is completely
arbitrary.

			Anthony.

-- 
Anthony R Fletcher        
  Room 2033, Building 12A,        http://dcb.cit.nih.gov/~arif
  National Institutes of Health,  arif@mail.nih.gov
  12A South Drive, Bethesda,      Phone: (+1) 301 402 1741.
  MD 20892-5624, USA.


  reply	other threads:[~2011-12-13 17:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12 15:46 Anthony R Fletcher
2011-12-12 16:37 ` TJ Luoma
2011-12-12 19:41 ` Wayne Davison
2011-12-13  7:15   ` Martin Richter
2011-12-13 16:07   ` Rory Mulvaney
2011-12-13 16:45     ` Jérémie Roquet
2011-12-13 16:59       ` Anthony R Fletcher
2011-12-13 18:08         ` Daniel Shahaf
2011-12-13 16:49     ` Christoph (Stucki) von Stuckrad
2011-12-13 17:31       ` Bart Schaefer
2011-12-13 17:04     ` Rory Mulvaney
2011-12-13 17:32       ` Anthony R Fletcher [this message]
2011-12-13 18:04         ` Jérémie Roquet
2011-12-13 18:20           ` Stephane Chazelas
2011-12-13 19:19             ` Anthony R Fletcher
2011-12-13 10:01 ` Peter Stephenson
2011-12-13 17:10   ` Bart Schaefer
2011-12-13 20:42     ` Rory Mulvaney
2011-12-13 17:45 ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111213173237.GA10838@cosy.cit.nih.gov \
    --to=arif@mail.nih.gov \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).