#!/usr/bin/env perl
use strict;
use warnings;

my @args = ( [0, 30], [1000, 10], [500, 20] );

for my $argref (@args) {
   my $pid = fork();
   if ($pid) {  # parent
       print "Forked off child $pid with args @{$argref}\n";
   } else {
       exec('./child.pl', @{$argref});
       warn "Couldn't exec()!  Something wrong: $!\n";
       exit();
   }
}

print "Enter one of the pids mentioned above, or 'done' to exit\n";
while (my $input = <STDIN>) {
   chomp $input;
   last if lc $input eq 'done';

   kill('HUP', $input) or warn "Could not send SIGHUP to $input: $!";
}

while ((my $pid = wait()) != -1) {
   print "Child $pid just ended.\n";
}

print "Parent ending\n"; 


__END__
<p>The second program, <code>parent.pl</code>, will fork off three separate children
processes, each time printing the PID of the child just created.  The three children will
execute <code>child.pl</code> with arguments of (0, 30), (1000, 10), and (500, 20), 
respectively.  After creating the children, the parent will enter a loop getting input
from the user.  The user will enter a PID of one of the chidren, and the parent will
send a <code>SIGHUP</code> to that child.  When the user enters <code>done</code>,
the parent will then wait for all the children.  Each time one ends, it should print
the pid and exit value of each child.  When all children have ended, the parent should 
also end.</p>
