On Wed, 28 Aug 2002 11:46:05 -0700, [EMAIL PROTECTED] (David) wrote:
>Philip Montgomery wrote:
>> I am trying to figure out how to run process concurrently from Perl.  I
>> want the parent to spawn off the children and wait until they are complete
>> to continue.  I can get the child processes to run in serial, but I need
>> them to run in parallel.
>> The code I am using thus far is
>> for ($x;$x<4;$x++) {
>>     if ($pid=fork) {
>>     } else {
>>    system "mkdir dir$x";
>>     for ($i=1;$i<250;$i++) {
>>         open3(OUTPUT, INPUT, ERRORS, cd dir$x;make clean; make all);
>>         <code to process the output of the make commands and store into
>>         log files>

>
>you are forking a child, do a system() call, and execute some more code. 
>depends on what the "<code to process ...>" portion is, your child process 
>might(if it doesn't exit) goes back to the for loop and start to fork it's 
>own child. is that what you want?

Here try to run this one:
I think your open3 statement is not good, and having the cd dir$x in
there, looks like you are trying to recurse "cd" down 250 levels.
By the way cd should be chdir.

Anyways, run the code below, add some error checking, and
look at what it does. Then try to work in your open3 and make calls.
What are you trying to do anyways?
############################################################

#!/usr/bin/perl
use warnings;

if ($#ARGV < 0){@ARGV = qw( 1 2 3 4 )}
&afork (\@ARGV,4,\&mysub);
print "Main says: All done now\n";

sub mysub{
 my $x = $_[0];
 system "mkdir dir$x";
 chdir "dir$x"or die $!; 
 for ($i=1;$i<250;$i++) {
 system "touch $i-$x";

#alot of problems in here 
# open3(OUTPUT, INPUT, ERRORS, cd dir$x;make clean; make all);  
#<code to process the output of the make commands and store into log 

}
}

##################################################
sub afork (\@$&) {
my ($data, $max, $code) = @_;
my $c = 0;
foreach my $data (@$data) {
wait unless ++ $c <= $max;
die "Fork failed: $!\n" unless defined (my $pid = fork);
exit $code -> ($data) unless $pid;
}
1 until -1 == wait;
}
#####################################################






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to