Last active
July 23, 2018 20:33
-
-
Save progrium/0ac0248f70e2adce964f to your computer and use it in GitHub Desktop.
Creates a co-dependent process cluster, the first half of a "one for all" supervision strategy
This file contains hidden or 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
#!/bin/bash | |
codep() { | |
set -eo monitor | |
trap 'kill $(jobs -p) &> /dev/null' EXIT | |
trap 'exit 2' CHLD | |
for child in "$@"; do | |
$child & | |
done | |
wait | |
} | |
[[ "$0" == "$BASH_SOURCE" ]] && codep "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example:
Process exits and all children will be killed after 3 seconds.