Skip to content

Instantly share code, notes, and snippets.

@theneubeck
Created December 13, 2018 18:01
Show Gist options
  • Save theneubeck/cabecab14b1fd95fddb2d2b489d2e174 to your computer and use it in GitHub Desktop.
Save theneubeck/cabecab14b1fd95fddb2d2b489d2e174 to your computer and use it in GitHub Desktop.
wait-and-kill-subprocesses (on ctrl+c)
#!/usr/bin/env bash
echo "Hej"
function cleanup {
kill $pid1
kill $pid2
exit
}
trap cleanup SIGHUP SIGINT SIGTERM
sleep 100 &
pid1=$!
sleep 200 &
pid2=$!
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment