Last active
September 7, 2022 20:40
-
-
Save arouene/70159b6d3036733ca7aff85847ced348 to your computer and use it in GitHub Desktop.
Interruptible process watcher
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 | |
declare -a JOBS | |
JOBS=("sleep 1" "sleep 2" "sleep 3") | |
cleanup() { | |
trap "" SIGTERM | |
kill 0 | |
wait | |
echo "Exited" | |
exit 0 | |
} | |
trap cleanup SIGINT SIGTERM | |
for job in "${JOBS[@]}"; do | |
( | |
# Always restart the jobs | |
while true; do | |
echo "Running: $job" | |
/bin/sh -c "$job" | |
# if a shell is not needed use `eval "$job"` instead | |
done | |
) & | |
done | |
wait | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment