if ((my $pid == fork()) == 0) { exec 'ghostscript', @args; } else { my $slept; while($slept++ < $alarmtime) { sleep 1; last unless kill 0, $pid; # see if it's still alive } kill 0, $pid or kill 15, $pid; wait; }