Prevent double kill in WaitForTaskCompletion

pull/60/head
deajan 8 years ago
parent fd2dfabce2
commit f052422c44

@ -598,30 +598,8 @@ function WaitForTaskCompletion {
WAIT_FOR_TASK_COMPLETION=""
while [ ${#pidsArray[@]} -gt 0 ]; do
Logger "Hey hey ${#pidsArray[@]} is $(joinString , ${pidsArray[@]})" "WARN"
newPidsArray=()
for pid in "${pidsArray[@]}"; do
if kill -0 $pid > /dev/null 2>&1; then
# Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :)
#TODO(high): have this tested on *BSD, Mac & Win
pidState=$(ps -p$pid -o state= 2 > /dev/null)
if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then
newPidsArray+=($pid)
fi
else
# pid is dead, get it's exit code from wait command
wait $pid
retval=$?
if [ $retval -ne 0 ]; then
errorcount=$((errorcount+1))
Logger "${FUNCNAME[0]} called by [$caller_name] finished monitoring [$pid] with exitcode [$result]." "DEBUG"
if [ "$WAIT_FOR_TASK_COMPLETION" == "" ]; then
WAIT_FOR_TASK_COMPLETION="$pid:$result"
else
WAIT_FOR_TASK_COMPLETION=";$pid:$result"
fi
fi
fi
done
Spinner
if [ $counting == true ]; then
@ -661,6 +639,30 @@ function WaitForTaskCompletion {
fi
fi
for pid in "${pidsArray[@]}"; do
if kill -0 $pid > /dev/null 2>&1; then
# Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :)
#TODO(high): have this tested on *BSD, Mac & Win
pidState=$(ps -p$pid -o state= 2 > /dev/null)
if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then
newPidsArray+=($pid)
fi
else
# pid is dead, get it's exit code from wait command
wait $pid
retval=$?
if [ $retval -ne 0 ]; then
errorcount=$((errorcount+1))
Logger "${FUNCNAME[0]} called by [$caller_name] finished monitoring [$pid] with exitcode [$result]." "DEBUG"
if [ "$WAIT_FOR_TASK_COMPLETION" == "" ]; then
WAIT_FOR_TASK_COMPLETION="$pid:$result"
else
WAIT_FOR_TASK_COMPLETION=";$pid:$result"
fi
fi
fi
done
pidsArray=("${newPidsArray[@]}")
sleep $SLEEP_TIME
done

Loading…
Cancel
Save