[Pikes-peak-pm] Firing Off Child Processes

Thomas Harrington tph at acm.org
Thu Oct 7 16:13:54 CDT 2004


On Oct 7, 2004, at 5:25 AM, John Evans wrote:
> I have several datafiles in a directory. I need to process each one, 
> but
> the processing can take anywhere from a few seconds to fifteen 
> minutes. I
> don't want the entire process waiting on a long one while shorter ones 
> are
> in line to be done.
>
> I assume that I need to fire off a child process to handle the actual
> processing, but I'm not sure how to go about doing this. I thought 
> fork()
> was the answer, but it appears (I may be missing something here, 
> though)
> that fork() will only make a new copy of the current program. That's 
> not
> what I'm looking for, but if fork() is the only option that I have, 
> then I
> can make it work.

I had to do something like this a couple of jobs ago-- where processing 
time could range from seconds to hours depending on the specific input. 
  I found the quickest approach to be "make".  The individual processes 
I needed to run all took an input file and generated an output file.  
So I wrote a Makefile to reflect how this was done.  Then "make -j N" 
kept multiple copies of the script running in parallel until everything 
was done.  No sense worrying about fork() or system() or a custom 
solution or whatever when make was already prepared to do the job for 
me.

That's with GNU make, of course, I'm not certain if non-GNU makes have 
this feature.

-- 
Tom Harrington
tph at acm.org



More information about the Pikes-peak-pm mailing list