Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AlexDaniel
Last active June 27, 2020 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDaniel/c624be8c78b062e56e2c8b5197795a8e to your computer and use it in GitHub Desktop.
Save AlexDaniel/c624be8c78b062e56e2c8b5197795a8e to your computer and use it in GitHub Desktop.
#!/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