Skip to content

Commit 5a568b5

Browse files
committed
fix: eliminate bug with looking up child pids
1 parent fc81ec2 commit 5a568b5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

bin/ctl.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,34 @@ function start_services {
8787
fi
8888
}
8989

90+
function trim {
91+
local str="$*"
92+
93+
str="${str#"${str%%[![:space:]]*}"}"
94+
str="${str%"${str##*[![:space:]]}"}"
95+
96+
printf '%s' "$str"
97+
}
98+
9099
function pids_list {
91-
local pid="$1"
92-
local pids child_pid
100+
local pid pids child_pid
101+
102+
pid=$(trim "$1")
93103

94104
if [[ -z "$pid" ]]; then
95105
return 0
96106
fi
97107

98-
echo "$1"
108+
echo "$pid"
99109
mapfile -t pids < <(ps --ppid "$pid" -o pid | awk 'NR>1')
100110

101111
if [[ ! 0 -eq "${#pids[@]}" ]]; then
102112
for child_pid in "${pids[@]}"; do
103-
pids_list "$child_pid"
113+
child_pid=$(trim "$child_pid")
114+
115+
if [[ -n "$child_pid" ]]; then
116+
pids_list "$child_pid"
117+
fi
104118
done
105119
fi
106120
}

0 commit comments

Comments
 (0)