Modification of pids is local (to subshell caused by pipeline).
pids was modified in a subshell. That change might be lost.
local wait
# read uses all vars within pipe subshell
+ rm -f PIDS
print_procs_by_tag_ "$@" | while read -r pid wait; do
if test -n "$pid" ; then
echo "Killing tagged process: $pid ${wait:0:120}..."
kill -TERM "$pid" 2>/dev/null || true
fi
- pids="$pids $pid"
+ echo "$pid" >> PIDS
done
+ test -f PIDS || return 0
+
# wait if process exited and eventually -KILL
wait=0
- for pid in $pids ; do
+ for pid in $(< PIDS) ; do
while ps "$pid" > /dev/null && test "$wait" -le 10; do
sleep .2
wait=$(( wait + 1 ))