Skip to content

Instantly share code, notes, and snippets.

@progrium
Last active July 23, 2018 20:33
Show Gist options
  • Save progrium/0ac0248f70e2adce964f to your computer and use it in GitHub Desktop.
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
#!/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 "$@"
@progrium
Copy link
Author

progrium commented Jun 5, 2014

Usage example:

$ codep "sleep 10" "sleep 3" "sleep 30"

Process exits and all children will be killed after 3 seconds.

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