Re: [SLUG] bash script fork children

From: Dylan William Hardison (dylan@hardison.net)
Date: Wed Jan 03 2007 - 17:03:17 EST


Spake Mike Branda on Wednesday, January 03, 2007 at 02:08PM -0500:
> 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.e.
>
> mbranda:~> pstree
>
> ├─kdeinit─┬
> │ ├─konsole───bash───image_resize.sh─┬─convert
> |─convert
> |─convert
> |─convert
>
>
> Right now I just create 4 different dirs and run 4 instances of the
> shell script ( which calls convert ) on them. This makes the batching
> of a few hundred images go much faster. I know there's got to be a way
> to fork more instances and count how many are active. I figure the for
> loop will have to be smart in some way to fork and move on to the next
> image in $dir until the max of 4 instances is reached.
>

I don't do much shell scripting, but prepending '&' to the end of a sh
command is a fork.

Though the best way to do this would probably be using make...
hmm...

-- 
"You could be sad, but I'd rather you not be.
Don't dwell on the negative, just the positivity"
              -- David "Ziggy" Marley, "Beautiful Day" (song)
-
GPG Fingerprint: E3CD FDAB 82C4 14FD 7B57  430B 770E 0EAF FB53 12C2
-----------------------------------------------------------------------
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:13 EDT