blob: 03586896d98899a24a552427edca9bf7e9d54139 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/bin/bash
set -ue
get_parent () {
ps hoppid p$1
}
get_children () {
ps hopid --ppid "$1"
}
get_ancestors () {
case $1 in
0|1|'') :
;; *) get_ancestors $(get_parent $1)
esac
echo "$1"
}
get_descendents () {
for c in $(get_children "$1")
do echo "$c"
get_descendents "$c"
done
}
declare -i p
for p in "$@"
do
[[ $p -ne 0 ]] && {
get_ancestors "$p"
get_descendents "$p"
} | {
readarray -t pids
ps -Hf "${pids[@]}" | sed "/^[^ ]* *$p /s/.*/[1m&[0m/"
}
done
|