-
-
Save AlexDaniel/c624be8c78b062e56e2c8b5197795a8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
spurt ‘/tmp/bash-catcher’, 「#!/bin/bash | |
trap "echo INT" INT | |
trap "echo TERM" TERM | |
trap "echo USR1" USR1 | |
for i in {1..4}; do | |
/bin/sleep 1 | |
done | |
」; | |
with Proc::Async.new(‘/bin/bash’, ‘/tmp/bash-catcher’, :w) -> $proc { | |
react { | |
whenever $proc.start { | |
say ‘finished’; | |
say .?exitcode; | |
say .?signal; | |
done | |
} | |
whenever Promise.in(0.5) { | |
$proc.kill(SIGTERM); | |
} | |
whenever Promise.in(1.0) { | |
$proc.kill(SIGTERM); | |
} | |
whenever Promise.in(1.5) { | |
$proc.kill(SIGKILL); | |
} | |
whenever Promise.in(2.5) { | |
note ‘SIGKILL not sent, absolute failure’; | |
exit 42 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment