Re: [SLUG] bash script fork children

From: Mike Branda (mike@wackyworld.tv)
Date: Thu Jan 04 2007 - 12:32:48 EST


On Wed, 2007-01-03 at 17:49 -0500, Ian C. Blenke wrote:
> Eben King wrote:
>
> > On Wed, 3 Jan 2007, Mike Branda wrote:
> >
> >> So I've been playing with ImageMagick to batch process psd files into
> >> flattened jpgs. I have a bash script that runs a for loop with
> >> "convert" on a directory. What I have noticed is that in xosview on my
> >> Dual Intel Hyper Threaded box ( shows up as 4 cpu's cause of the HT ),
> >> only one ( or one half? ) CPU is doing all the work. Makes sense
> >> because of the whole user space kernel space thing and I don't really
> >> need both CPU's working on pieces of the same image anyway.
> >>
> >> What I would like though is a way to fork multiple children in the loop
> >> to start additional instances of convert until 4 are active. Then wait
> >> until one exits and then start on the next image. 4 active converts
> >> always until all the images are processed.
> >
>
> I'm sure we've been through this before. Isn't this in the FAQ yet? If
> not, it probably should be.
>
> The easiest way is with parallelized xargs:
>
> $ find . -name '*.jpg' | sed -e 's/.jpg$//' | xargs -P4 -l1 -i
> convert {}.jpg {}.png
>
> The -P flag for xargs is a _wonderful_ thing to learn. Do it now, it
> will forever save you time. I use it daily in our huge farm of linux
> servers, makes for far more bearable adminning.
>
> The other ways (already suggested) are to script something with
> subshells and a queue, or wrap it in a Makefile and use make -j4.
>
> - Ian C. Blenke <ian@blenke.com> <icblenke@nks.net> http://ian.blenke.com/

Ian,

Thanks for the input. I searched my local list history from 2004 for
xargs and only found a few things. I'll read up on it.

Mike

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:27:38 EDT