5 # phier: Show process tree incorporating a process.
6 # Notes: phier functions similarly (but not identically) to Solaris ptree.
7 # Usage: phier [options] <pid>
8 # Options: -s <search> Stop hierarchy at this process name.
9 # Example: phier -s sshd $$
12 function find_parent() {
16 if [ -z "$child" ]; then
17 echo >&2 "No child to find."
21 cmd=$(ps -o comm= -p $child)
22 pid=$(ps -o pid= -p $child)
23 ppid=$(ps -o ppid= -p $child)
25 # echo >&2 "Finding from $child ($top) $pid/$ppid/$cmd"
27 if [ -z "$pid" ]; then
28 echo >&2 "Can't find PID $child!"
32 if [ ! -z "$top" ]; then
33 if [ "$cmd" = "$top" ]; then
39 if [ $pid = 1 -o $ppid = 1 ]; then
44 find_parent $ppid $top
50 while getopts ":s:" opt; do
58 echo >&2 "phier: Print process hierarchy for a process."
59 echo >&2 "Usage: phier [options] <pid>"
60 echo >&2 "Options: -s <search> Stop hierarchy at this process name."
61 echo >&2 "Example: phier -s sshd $$"
65 parent=$(find_parent "$1" "$top")