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

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; } }

Replies are listed 'Best First'.
Re^3: Using SIG{ALRM} within while loop.
by evroom (Novice) on Jul 24, 2019 at 11:23 UTC

    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 :-) ).