From 3bbb022045ae3726420d124f38b5c11755e42d07 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 14 Jun 2019 20:07:18 +0000 Subject: [PATCH] Add kill_node utility function --- scripts/node.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/node.sh b/scripts/node.sh index 6239e8fe7..41bec7f39 100755 --- a/scripts/node.sh +++ b/scripts/node.sh @@ -237,6 +237,29 @@ kill_child() { kill "${pid}" } +# Kill nodes that are direct child of this script (pid $$), +# i.e. run directly from main loop. +kill_node() { + local pids pid delay + + msg "finding node processes that are our children" + pids=$( + ps axcwwo "pid=,ppid=,command=" | + awk -v me=$$ '$2 == me && $3 == "harmony" { print $1; }' + ) + msg "found node processes: ${pids:-""}" + for pid in ${pids} + do + delay=0 + while kill_child ${pid} + do + sleep ${delay} + delay=1 + done + msg "pid ${pid} no longer running" + done +} + { # TODO ek – implement me } &