helper process that rather dumbly starts gnunet peers
[oweals/gnunet.git] / contrib / peerStartHelper.pl
1 #!/usr/bin/perl
2 use strict;
3
4 my $max_outstanding = 300;
5
6 $ARGV[0] || die "No directory provided for peer information, exiting!\n";
7
8 my $directory = $ARGV[0];
9 my @config_files = `find $directory -iname gnunet-testing-config*`;
10 my @child_arr = {};
11 my $count = 0;
12 my $outstanding = 0;
13 foreach my $file (@config_files)
14 {
15   chomp($file);
16   #print "Starting GNUnet peer with config file $file\n";
17   my $pid = fork();
18   if ($pid == -1) 
19   {
20    die;
21   } 
22   elsif ($pid == 0) 
23   {
24     exec "gnunet-arm -q -c $file -s"  or die;
25   }
26
27   if ($pid != 0)
28   {
29     push @child_arr, $pid;
30     $count++;
31     $outstanding++;
32     if ($outstanding > $max_outstanding)
33     {
34       for (my $i = 0; $i < $max_outstanding / 5; $i++)
35       {
36         #print "Too many outstanding peers, waiting!\n";
37         waitpid($child_arr[0], 0);
38         shift(@child_arr);
39         $outstanding--;
40       }
41     }
42   }
43 }
44
45 print "All $count peers started (waiting for them to finish!\n";
46
47 while ($outstanding > 0)
48 {
49   waitpid($child_arr[0], 0);
50   shift(@child_arr);
51   $outstanding--;
52   if ($outstanding % 50 == 0)
53   {
54     print "All $count peers started (waiting for $outstanding to finish!\n";
55   }
56 }
57
58 while (wait() != -1) {sleep 1}
59
60 print "All $count peers started!\n";
61
62