#!/usr/bin/perl use strict; use Term::ReadKey; $SIG{ALRM} = "AlarmHandler"; my $childPid = fork(); die unless defined($childPid); if ( ! $childPid ) { # in child sleep 10; exit 0; } # in parent print "\nPlease do xyz (or hit A to abort).\n"; alarm (1); # Check for keystroke every second if (waitpid($childPid, 0) > 0) { my ($rc, $sig, $core) = ($? >> 8, $? & 127, $? & 128); if ($core) { print "PID $childPid dumped core\n"; } elsif ($sig == 9){ print "PID $childPid was killed!\n"; } else { print "PID $childPid returned $rc"; } } else { print "Where did PID $childPid go??"; # When AlarmHandler runs, waitpid exits with -1, so gets here. } alarm (0); exit 0; sub AlarmHandler() { open(TTY, "