Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Multi-core loops



I found a pretty/small solution (but not optimized)

http://stackoverflow.com/questions/38160/parallelize-bash-script

I'm quoting the solution (the solution can be used as-is in zsh too)

> Here an alternative solution that can be inserted into .bashrc and used for
> everyday one liner:
>
> function pwait() {
>     while [ $(jobs -p | wc -l) -ge $1 ]; do
>         sleep 1
>     done
> }
>
> To use it, all one has to do is put & after the jobs and a pwait call, the
> parameter gives the number of parallel processes:
>
> for i in *; do
>     do_something $i &
>     pwait 10
> done
>
> It would be nicer to use wait instead of busy waiting on the output of jobs
> -p, but there doesn't seem to be an obvious solution to wait till any of the
> given jobs is finished instead of a all of them.
>

-- 
ÂDans la vie, rien n'est à craindre, tout est à comprendreÂ
Marie Sklodowska Curie.



Messages sorted by: Reverse Date, Date, Thread, Author