You can always walk the ancestry tree by hand using `ps -o ppid=`:
#! /bin/bash -
pid=${1?Please give a pid}
while
[ "$pid" -gt 0 ] &&
read -r ppid name < <(ps -o ppid= -o comm= -p "$pid")
do
printf '%s\
' "$pid $name"
pid=$ppid
done
Or to avoid running `ps` several times:
#! /bin/sh -
pid=${1?Please give a pid}
ps -Ao pid= -o ppid= -o comm= |
awk -v p="$pid" '
{
pid = $1; ppid[pid] = $2
sub(/([[:space:]]*[[:digit:]]+){2}[[:space:]]*/, "")
name[pid] = $0
}
END {
while (p) {
print p, name[p]
p = ppid[p]
}
}'