Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created March 24, 2018 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/2f0444cadef5b3546fca0eec749b4b70 to your computer and use it in GitHub Desktop.
Save ORESoftware/2f0444cadef5b3546fca0eec749b4b70 to your computer and use it in GitHub Desktop.
job control
#!/usr/bin/env bash
function wait_for_subshells_to_exit() {
set -m; # allow for job control
for job in `jobs -p`; do
process_info="$(ps -o comm | grep ${job})"
code=0;
wait ${job} || code=$?
if [[ "${code}" != "0" ]]; then
echo "A job (subshell) failed with exit code => ${code}" ;
echo "$process_info";
exit 1;
fi
done
}
false &
wait_for_subshells_to_exit
echo "lol"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment