1. use POSIX ":sys_wait_h"; 2. my $loop = 1; 3. $loop = $ARGV[0] if defined $ARGV[0]; 4. my $timeout = 10; 5. my $child = fork(); 6. unless ( $child ) { 7. # Child 8. exec( "perl count.pl $loop" ); 9. exit 0; 10. } 11. 12. sleep( $timeout ); 13. my $kid = waitpid( $child, WNOHANG ); 14. if( $kid != -1 ) { 15. print "The child is still running! Kill the process: $child...\n"; 16. kill( 9, $child ); 17. } 18. else { print "no timeout\n"; } #### 1. my $loop = 1; 2. my $iterator = 1; 3. $loop = $ARGV[0] if defined $ARGV[0]; 4. for( ; $iterator <= $loop ; $iterator++ ) { 5. sleep( 1 ); 6. print "$iterator($$)...\n"; 7. } #### 1. local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required 2. alarm 10; 3. $child_pid = fork(); 4. if( $child_pid ) { 5. print "Child_pid = $child_pid\n"; 6. $pid2 = waitpid( $child_pid, 0 ); 7. } 8. elsif( $child_pid == 0 ) { 9. print "child pid= $$\n"; 10. exec( "ratlperl count.pl $x" ); 11. exit( 0 ); 12. }