improve handling / killing of hanging background procs
This commit is contained in:
@@ -566,7 +566,7 @@ declare -A pidtable
|
|||||||
first_run=true
|
first_run=true
|
||||||
while :; do
|
while :; do
|
||||||
# Check if main is still alive and exit otherwise.
|
# Check if main is still alive and exit otherwise.
|
||||||
ps -p $main_pid > /dev/null || break
|
ps -p $main_pid >/dev/null || break
|
||||||
|
|
||||||
[ -v EPOCHSECONDS ] && now=$EPOCHSECONDS || now=$(date +%s)
|
[ -v EPOCHSECONDS ] && now=$EPOCHSECONDS || now=$(date +%s)
|
||||||
for func in "${!DATA_FUNCS[@]}"; do
|
for func in "${!DATA_FUNCS[@]}"; do
|
||||||
@@ -600,16 +600,20 @@ while :; do
|
|||||||
fi
|
fi
|
||||||
data=$(timeout 1 cat <&$fd)
|
data=$(timeout 1 cat <&$fd)
|
||||||
rc=$?
|
rc=$?
|
||||||
|
eval "exec $fd>&-"
|
||||||
|
fdtable[$func]=-1
|
||||||
pid=${pidtable[$func]}
|
pid=${pidtable[$func]}
|
||||||
if (( rc == 124 )); then
|
if (( rc == 124 )); then
|
||||||
echo "gathering: timeout receiving data from $func (PID $pid, FD $fd), killing process" >&2
|
echo "gathering: timeout receiving data from $func (PID $pid, FD $fd), killing process" >&2
|
||||||
kill -9 $pid
|
kill -SIGTERM $pid
|
||||||
|
sleep 1
|
||||||
|
ps -p $pid >/dev/null && kill -SIGKILL $pid
|
||||||
|
rc=137
|
||||||
|
else
|
||||||
|
wait $pid
|
||||||
|
rc=$?
|
||||||
fi
|
fi
|
||||||
wait $pid
|
echo "gathering: $func (PID $pid, FD $fd) exited with rc = $rc" >&$DEBUGLOG
|
||||||
rc=$?
|
|
||||||
echo "gathering: $func exited (rc = $rc)" >&$DEBUGLOG
|
|
||||||
eval "exec $fd>&-"
|
|
||||||
fdtable[$func]=-1
|
|
||||||
if (( rc == 0 )) && [ -n "$data" ]; then
|
if (( rc == 0 )) && [ -n "$data" ]; then
|
||||||
echo "gathering: sending data to main" >&$DEBUGLOG
|
echo "gathering: sending data to main" >&$DEBUGLOG
|
||||||
echo "$data" 1>&$DATAIN
|
echo "$data" 1>&$DATAIN
|
||||||
|
|||||||
Reference in New Issue
Block a user