Skip to content

Instantly share code, notes, and snippets.

@lox
Last active November 4, 2019 01:49
Show Gist options
  • Save lox/ba545dff29ff2fa1f027010ecec4d65b to your computer and use it in GitHub Desktop.
Save lox/ba545dff29ff2fa1f027010ecec4d65b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
terminate(){
printf "Terminating child process $$ after signal."
exit 1
}
printf "Running $0, pid is %d, pgid is %d\n" "$$" "$(ps -o pgid= $$)"
trap 'echo "Got an INT signal"; terminate' INT
trap 'echo "Got a TERM signal"; terminate' TERM
trap 'echo "Got a QUIT signal"; terminate' QUIT
trap 'echo "Got a HUP signal"; terminate' HUP
pstree -p $$
sleep 100
#!/bin/bash
set -euo pipefail
terminate(){
printf "Terminating parent process $$ after signal."
exit 1
}
printf "Running $0, pid is %d, pgid is %d\n" "$$" "$(ps -o pgid= $$)"
trap 'echo "Got an INT signal"; terminate' INT
trap 'echo "Got a TERM signal"; terminate' TERM
trap 'echo "Got a QUIT signal"; terminate' QUIT
trap 'echo "Got a HUP signal"; terminate' HUP
bash ./child.sh
steps:
- label: "Testing implicit shell"
commands:
#- trap "kill -- -\$\$" TERM
- chmod +x ./parent.sh
- ./parent.sh
- true
- label: "Testing explicit shell"
command: ./parent.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment