#!/usr/bin/perl use strict; use warnings; use Time::Local; use Time::HiRes qw[ time ]; use POSIX ":sys_wait_h"; my $timeout = 3; my $Command = qq(echo 'Hallo, sleeping for 120 seconds ...'; sleep 120 2>&1); my $pid = open (COMMAND, '-|', "$Command"); print "ran command with pid=$pid\n"; my $iters = 0; while (kill 0, $pid) { eval { local $SIG{ALRM} = sub { print "resetting alarm $timeout\n"; alarm($timeout); die("TimerTriggerStatus\n"); }; if( ! $iters++ ){ print "setting alarm for the first time...\n"; alarm($timeout); } print "sleeping for $timeout and then will check command's output...\n"; sleep $timeout; print "now I may block for a long time waiting for command's output...\n"; print "command: ".."\n"; }; print "eval exited with this: ".$@."\n"; }