-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce usage of SCRIPT_NAME #546
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,13 +148,10 @@ function func_exit_handler() | |
|
||
# get ps command result as list | ||
local -a cmd_lst | ||
# $$ as current script pid | ||
# NOTICE: already test with $BASHPID: | ||
# it can output the same result of $$ | ||
# but the result could not be stored in the array | ||
readarray -t cmd_lst < <(pgrep -P $$ -a|grep -v "$SCRIPT_NAME") | ||
# can't run pgrep in any subshell because the latter would pollute the list | ||
if pgrep -P $$ -a > "$LOG_ROOT/children_left.txt"; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see any need to use a tmp file here, this will bring more trouble with sub-test And the whole logic is changed to me, the parent will still be killed by itself now. How is |
||
readarray -t cmd_lst < "$LOG_ROOT/children_left.txt" | ||
# now force kill target process which maybe block the script quit | ||
if [ ${#cmd_lst[@]} -gt 0 ]; then | ||
local line | ||
dlogw "Process(es) started by $SCRIPT_NAME are still active, killing these process(es):" | ||
for line in "${cmd_lst[@]}" | ||
|
@@ -163,6 +160,8 @@ function func_exit_handler() | |
dlogw "Kill cmd:'${line#* }' by kill -9" | ||
kill -9 "${line%% *}" | ||
done | ||
else | ||
rm "$LOG_ROOT/children_left.txt" | ||
fi | ||
|
||
# check if function already defined. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked
pgrep -P $$ -a
it will show the script it self, how do you remove it from the listThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong, demo: