in reply to Re: Fork and wait question
in thread Fork and wait question

kyle is right - your call to wait is in the child and it should be in the parent. Actually, since it is right after the exec it will never get called under normal circumstances.

To spawn a new child process, use:

die "unable to fork: $!" unless (defined(my $id = fork()); if ($id == 0) { exec($testpath) or die "unable to exec $testpath: $!\n"; }
and after the spawning loop, use:
while (wait > -1) {};
to wait for all of your children to terminate.

Replies are listed 'Best First'.
Re^3: Fork and wait question
by chris68805 (Initiate) on Jun 12, 2008 at 16:51 UTC
    ok, I I added what you requested. However it still will continue the program and finish. I can pull up process on my linux and it shows the two instances of the chirp_md5sum program running.
    $index=0; my $inputfile="perloutput"; my $endfile=".txt "; my $smb="> "; my $outputfile="output"; my $smb2="&"; while ($index<2) { my $testpath="chirp_md5sum "; $testpath=$testpath.$inputfile.$index.$endfile.$smb.$outputfile.$in +dex.$endfile.$smb2; chomp $testpath; print ("$testpath \n"); $id=fork(); if ($id == 0) { exec($testpath) or die "unable to exec $testpath: $!\n"; } $index++; } while (wait > -1) {};