programming-examples/perl/SystemFunction/The wait function.pl
2019-11-15 12:59:38 +01:00

24 lines
486 B
Perl

#!/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: " );
}