in reply to Using SIG{ALRM} within while loop.

Here's a quick and dirty solution in Perl6:
perl6 -e 'my $a = Proc::Async.new: "bash", "-c", "echo \"Hallo, sleepi +ng for 120 seconds ...\"; sleep 10"; $*SCHEDULER.cue(-> { say "In han +dler..." }, in => 1, every => 2); await $a.start'
If you want some idea as to more complex options, see this page: https://docs.perl6.org/type/Proc::Async

Replies are listed 'Best First'.
Re^2: Using SIG{ALRM} within while loop.
by Xliff (Initiate) on Jul 24, 2019 at 11:15 UTC
    Another, more in-depth version of the above, that gives you more control over script output:
    my $proc = Proc::Async.new: "bash", "-c", "echo \"Hallo, sleeping for 120 seconds ...\"; sleep 120"; react { whenever $proc.stdout.lines { # Act on output from command. In this case, we just print it. say ‘line: ’, $_ } whenever Supply.interval(10) { # Handler. Occurs every 10 seconds. say "In handler..." } whenever $proc.start { say ‘Proc finished: exitcode=’, .exitcode, ‘ signal=’, .signal; # Gracefully jump from the react block. # Also stops the handler! done; } whenever Promise.in(300) { # Optional time-out code that fires in 300 seconds [5 minutes] # Handle as you see fit, but it's probably best to end with: done; } }

      Thanks for the code and trying to help me out. I will first tryout threads. I already got it working; now busy with ending threads in a controlled way. For any questions I might have for which I cannot find an answer, I will create a new PerlMonks thread (how appropiate :-) ).