Skip to content

Commit 81a636a

Browse files
committed
exit handler: don't use a subshell to list children still running
Use a new children_left.txt log file instead. Using a subshell forced us to filter it out with grep -v $SCRIPT_NAME which is more complicated, incompatible with exec wrappers like multiple-pipeline-capture/playback.sh and incompatible with running concurrent instances. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent b762044 commit 81a636a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

case-lib/hijack.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ function func_exit_handler()
6464

6565
# get ps command result as list
6666
local -a cmd_lst
67-
# $$ as current script pid
68-
# NOTICE: already test with $BASHPID:
69-
# it can output the same result of $$
70-
# but the result could not be stored in the array
71-
readarray -t cmd_lst < <(pgrep -P $$ -a|grep -v "$SCRIPT_NAME")
67+
# can't run pgrep in any subshell because the latter would pollute the list
68+
if pgrep -P $$ -a > "$LOG_ROOT/children_left.txt"; then
69+
readarray -t cmd_lst < "$LOG_ROOT/children_left.txt"
7270
# now force kill target process which maybe block the script quit
73-
if [ ${#cmd_lst[@]} -gt 0 ]; then
7471
local line
7572
dlogw "Process(es) started by $SCRIPT_NAME are still active, kill these process(es):"
7673
for line in "${cmd_lst[@]}"
@@ -79,6 +76,8 @@ function func_exit_handler()
7976
dlogw "Kill cmd:'${line#* }' by kill -9"
8077
kill -9 "${line%% *}"
8178
done
79+
else
80+
rm "$LOG_ROOT/children_left.txt"
8281
fi
8382

8483
# check if function already defined.

0 commit comments

Comments
 (0)