use strict;
use warnings;

$| = 1;

my $num = 10;
my @childs = ();

for(1..$num) 
  {
  my $pid = fork();
  die "Fork ging schief: $!\n" unless(defined $pid); 
  if ($pid == 0)        # child
    {
    print "Hier ist Kind Nr. $_\n";
    sleep 5;
    exit(0);
    }
  else                 # parent
    {
    push(@childs, $pid);
    }
  }
print "Alle Kinder erzeugt\n";

foreach (@childs)   
  {
  waitpid($_, 0);
  print "Kind $_ gestorben\n";
  }
