#!/usr/bin/perl use strict; use warnings; use Time::Local; use Time::HiRes qw[ time ]; use POSIX ":sys_wait_h"; my $ReturnValue = 0; sub MainSub() { my $Sub = "MainSub"; my $SubReturnValue = 0; my $CommandLine; my $Command = qq(echo 'Hallo, sleeping for 120 seconds ...'; sleep 120 2>&1); open (COMMAND, '-|', "$Command"); while () { eval { local $SIG{ALRM} = sub { die("TimerTriggerStatus\n"); }; alarm(10); printf "%s : %s\n", scalar localtime(), "$Sub - timer set to 10 seconds"; chomp; $CommandLine = $_; printf "%s : %s\n", scalar localtime(), "$Sub - CommandLine received:\n$CommandLine"; }; if ( $@ eq "TimerTriggerStatus\n" ) { printf "%s : %s\n", scalar localtime(), "$Sub - timer triggered"; &TimerHandler; }; } close (COMMAND); return ($SubReturnValue); } # end of sub MainSub sub TimerHandler() { my $Sub = "TimerHandler"; my $SubReturnValue = 0; printf "%s : %s\n", scalar localtime(), "$Sub - timer expired"; alarm(10); printf "%s : %s\n", scalar localtime(), "$Sub - timer set to 10 seconds"; return ($SubReturnValue); } # end of sub TimerHandler sub TimerSub() { my $Sub = "TimerSub"; my $SubReturnValue = 0; printf "%s : %s\n", scalar localtime(), "$Sub - run after timer interrupt"; alarm(10); printf "%s : %s\n", scalar localtime(), "$Sub - timer set to 10 seconds"; return ($SubReturnValue); } # end of sub TimerSub #### MAIN #### printf "%s : %s\n", scalar localtime(), "BEGIN - MAIN"; ($ReturnValue) = &MainSub; printf "%s : %s\n", scalar localtime(), "END - MAIN";