Last active
August 29, 2015 07:29
-
-
Save jleskovar/f095520344f7ef83c4ae to your computer and use it in GitHub Desktop.
This file contains 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 | |
function displayPendingTasks() { | |
echo "The following machines are still running" | |
declare -A running | |
for i in ${!RUNNING_TASKS[@]}; do | |
if kill -0 $i > /dev/null 2>&1; then | |
echo "PID: $i Machine: ${RUNNING_TASKS[$i]}" | |
running[$i]="${RUNNING_TASKS[$i]}" | |
fi | |
done | |
read -p "Do you wish to kill these processes and stop waiting? [y/n]: " prompt | |
if [ "$prompt" == "y" ]; then | |
echo "Stopping processes." | |
kill -9 $(echo "${!running[@]}") | |
trap - INT | |
exit 0 | |
fi | |
wait | |
} | |
trap displayPendingTasks INT | |
declare -a RUNNING_TASKS | |
for i in `seq 10 20`; do | |
sleep 20 & | |
RUNNING_TASKS[$!]="machine-$i" | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment