fork - How to limit the child process in perl? -


i have written script includes generation of gcov in parallel.i succeeded in creating 17 child process @ time.but want create 6 child processes @ time,the 7th child should create after 1child process terminate.

sub gcov_parallel()   2 {   3     print "generating gcov...\n";   4     $kid;   5     $pid;   6     @list = (@iucall,@iurcall_init,@iurcall_term,@iurcall_uti,@nob,@nobcch,@nobcell,@nobrrc,@nobcall,@rnccall,@cellin     fo,@rnccom,@cellrrm,@uerrm,@uerrc,@uecall,@iupcded);   7     $len_list = scalar(@list);   8     $maxlen =0;   9     $count = 0;  10     $process = 0;  11     $total_components = scalar(@comp_list);  12  13     for(my $comp_count=0; $comp_count < $len_list ; ($comp_count=$comp_count+$no_of_machines))  14     {  15         #limiting child process 6  16         if($process == 6)  17         {  18             $pid = wait();  19             $process=$process-1;  20         }  21         else  22         {  23             $pid = fork();  24             if($pid eq 0)  25             {  26                 for(my $files_count = 0; $files_count < $no_of_machines; $files_count++)  27                 {  28                     $count =  $files_count+$comp_count;  29                     if($count < $len_list)  30                     {  31                         chomp($list[$count]);  32                         @list_gcda =`ls $list[$count]/*.gcda | sort`; &generate_gcov("$list[$count]",@list_gcda);  34                     }  35                 }  36                 wait();  37                 exit;  38             }  39             $process=$process+1;  40         }  41     }  42      43     {  44         $kid = waitpid(-1, 0);  45     }while $kid > 0;  46 }  observed while running script skipping files while generating gcov.                                                          

i think use paralel::forkmanager this.

there good tutorial on perlmonks paralel::forkmanager.

it simple:

my $manager = parallel::forkmanager->new( 6 );    foreach $command (@commands) {       $manager->start , next;       system( $command );       $manager->finish;    }; 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -