Skip to content

Instantly share code, notes, and snippets.

@ptrlv

ptrlv/trap Secret

Created September 24, 2019 14:55
Show Gist options
  • Save ptrlv/c5740b176578e4cbf7a85426419fc1bf to your computer and use it in GitHub Desktop.
Save ptrlv/c5740b176578e4cbf7a85426419fc1bf to your computer and use it in GitHub Desktop.
#!/bin/bash
function trap_handler() {
echo "Caught $1, signalling pilot PID: $pilotpid"
kill -s $1 $pilotpid
wait
}
trap 'trap_handler SIGTERM' SIGTERM
trap 'trap_handler SIGQUIT' SIGQUIT
trap 'trap_handler SIGSEGV' SIGSEGV
trap 'trap_handler SIGXCPU' SIGXCPU
trap 'trap_handler SIGUSR1' SIGUSR1
trap 'trap_handler SIGBUS' SIGBUS
sleep 30 &
pilotpid=$!
echo pilotpid: $pilotpid
wait $pilotpid
@ptrlv
Copy link
Author

ptrlv commented Sep 24, 2019

ps. you can test by sending a signal to the trap.sh process, not the pilotpid. Use pstree -p to get the correct pid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment