use strict; use warnings; sub child { $SIG{TERM} = sub { exit 0 }; for ( 1 .. 10 ) { print "Child: $_\n"; sleep 1; } exit 0; } die "Cannot fork: $!\n" unless defined( my $pid = fork ); $pid || child; for ( 1 .. 10 ) { print "Parent: $_\n"; kill 15 => $pid if $_ == 5; sleep 1; }