more refinement
This commit is contained in:
@@ -4,20 +4,18 @@
|
||||
tty=$1
|
||||
|
||||
# Construct process tree.
|
||||
children=();
|
||||
pids=( $(ps -o pid= -t $tty) )
|
||||
children=()
|
||||
pids=($(ps -o pid= -t $tty))
|
||||
|
||||
while read -r pid ppid
|
||||
do
|
||||
[[ -n pid && pid -ne ppid ]] && children[ppid]+=" $pid"
|
||||
done <<< "$(ps -Ao pid=,ppid=)"
|
||||
while read -r pid ppid; do
|
||||
[[ -n $pid && $pid -ne $ppid ]] && children[ppid]+=" $pid"
|
||||
done <<<"$(ps -Ao pid=,ppid=)"
|
||||
|
||||
# Get all descendant pids of processes in $tty with BFS
|
||||
idx=0
|
||||
while (( ${#pids[@]} > idx ))
|
||||
do
|
||||
pid=${pids[idx++]}
|
||||
pids+=( ${children[pid]-} )
|
||||
while ((${#pids[@]} > idx)); do
|
||||
pid=${pids[idx++]}
|
||||
pids+=(${children[pid]-})
|
||||
done
|
||||
|
||||
# Check whether any child pids are vim
|
||||
|
||||
Reference in New Issue
Block a user