#!/usr/bin/perl


use warnings;
use strict;

my ( $pid, $pid2 );
$| = 1;

if ( ( $pid = fork() ) && ( $pid2 = fork() ) ) {
   print( "I have to wait for my kids.\n" );
   my $straggler = wait();
   print( "Finally $straggler finished, now I can go.\n" );
}
elsif ( $pid && defined( $pid2 ) ) {
   print( "Kid 2: So is mine...\n" );
   exit();
}
elsif ( defined( $pid ) ) {
   print( "Kid 1: My parent is patient...\n" );
}
else {
   die( "Forking problems: " );
}