Skip to content

Commit 048f488

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 9bc74c8 commit 048f488

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
@@ -148,13 +148,10 @@ function func_exit_handler()
148148

149149
# get ps command result as list
150150
local -a cmd_lst
151-
# $$ as current script pid
152-
# NOTICE: already test with $BASHPID:
153-
# it can output the same result of $$
154-
# but the result could not be stored in the array
155-
readarray -t cmd_lst < <(pgrep -P $$ -a|grep -v "$SCRIPT_NAME")
151+
# can't run pgrep in any subshell because the latter would pollute the list
152+
if pgrep -P $$ -a > "$LOG_ROOT/children_left.txt"; then
153+
readarray -t cmd_lst < "$LOG_ROOT/children_left.txt"
156154
# now force kill target process which maybe block the script quit
157-
if [ ${#cmd_lst[@]} -gt 0 ]; then
158155
local line
159156
dlogw "Process(es) started by $SCRIPT_NAME are still active, killing these process(es):"
160157
for line in "${cmd_lst[@]}"
@@ -163,6 +160,8 @@ function func_exit_handler()
163160
dlogw "Kill cmd:'${line#* }' by kill -9"
164161
kill -9 "${line%% *}"
165162
done
163+
else
164+
rm "$LOG_ROOT/children_left.txt"
166165
fi
167166

168167
# check if function already defined.

0 commit comments

Comments
 (0)