3 function find_parent() {
7 cmd=$(ps -o comm= -p $child)
8 pid=$(ps -o pid= -p $child)
9 ppid=$(ps -o ppid= -p $child)
11 # echo >&2 "Finding from $child ($top) $pid/$ppid/$cmd"
13 if [ -z "$pid" ]; then
14 echo >&2 "Can't find PID $child!"
18 if [ ! -z "$top" ]; then
19 if [ "$cmd" = "$top" ]; then
25 if [ $ppid = 1 ]; then
30 find_parent $ppid $top
35 echo >&2 "phier: Print process hierarchy for a process."
36 echo >&2 "Usage: phier <pid> [<search>]"
37 echo >&2 "Notes: If a search term is given the hierarchy will stop after finding a"
38 echo >&2 " process matching that search term."
39 echo >&2 "Example: phier $$ sshd"
43 parent=$(find_parent ${1+"$@"})