aboutsummaryrefslogtreecommitdiff
path: root/contrib/peerStartHelper.pl
blob: c3994c32b4acfeada3388b7d6b21ef67e944d85a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
use strict;

my $max_outstanding = 300;

$ARGV[0] || die "No directory provided for peer information, exiting!\n";

my $directory = $ARGV[0];
my @config_files = `find $directory -iname gnunet-testing-config*`;
my @child_arr = {};
my $count = 0;
my $outstanding = 0;
foreach my $file (@config_files)
{
  chomp($file);
  #print "Starting GNUnet peer with config file $file\n";
  my $pid = fork();
  if ($pid == -1) 
  {
   die;
  } 
  elsif ($pid == 0) 
  {
    exec "gnunet-arm -q -c $file -s"  or die;
  }

  if ($pid != 0)
  {
    push @child_arr, $pid;
    $count++;
    $outstanding++;
    if ($outstanding > $max_outstanding)
    {
      for (my $i = 0; $i < $max_outstanding / 5; $i++)
      {
	#print "Too many outstanding peers, waiting!\n";
	waitpid($child_arr[0], 0);
	shift(@child_arr);
	$outstanding--;
      }
    }
  }
}

print "All $count peers started (waiting for them to finish!\n";

while ($outstanding > 0)
{
  waitpid($child_arr[0], 0);
  shift(@child_arr);
  $outstanding--;
  if ($outstanding % 50 == 0)
  {
    print "All $count peers started (waiting for $outstanding to finish!\n";
  }
}

while (wait() != -1) {sleep 1}

print "All $count peers started!\n";