Merge from vendor branch BIND:
[dragonfly.git] / tools / tools / mid / mid-master
1 #!/usr/local/bin/perl
2
3 if ($#ARGV < 1) {
4     die "usage master counter command comandargs ... \n";
5 }
6
7 $count = $ARGV[0]; shift @ARGV;
8 @command = @ARGV;
9 $file = pop(@command);
10 undef @ARGV;
11 $debug = 0;
12
13 for($i = 0; $i < $count; $i ++) {
14     @c = (@command, "$file.$i");
15     warn "Start process: $i @c\n" if $debug;
16     open("OUT$i", "| @c") || die "open @c\n";
17     select("OUT$i"); $| = 1;
18 }
19 select(STDOUT);
20
21 $n = 0;
22 while(<>) {
23     $o = 'OUT' . ($n % $count);
24     print $o $_;
25     warn "$o $_" if $debug;
26     $n++
27 }
28
29 for($i = 0; $i < $count; $i ++) {
30     warn "Close process $i\n" if $debug;
31     close("OUT$i") || warn "close OUT$i: $!\n";
32 }
33