Skip to content

Instantly share code, notes, and snippets.

@jleskovar
Last active August 29, 2015 07:29
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 jleskovar/f095520344f7ef83c4ae to your computer and use it in GitHub Desktop.
Save jleskovar/f095520344f7ef83c4ae to your computer and use it in GitHub Desktop.
#!/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