Maybe if with ps -ef:
awk -vPID=$1 ' function getParent ( pid ) { if (pid == "" || pid == "0") return; while ("ps -ef | grep "pid | getline) { if ($2 == pid) { print $8"("$2") Called By "$3; getParent($3); break; } } close ("ps -ef") } BEGIN { getParent(PID) } '
This is an ugly assumption about ps output column and order. In fact, one ps -ef run contains all the necessary information. It is not worth the time, I still recommend updating psmisc, it will not hurt.
EDIT: imitation using the single-run ps -ef:
ps -ef | awk -vPID=$1 ' function getpp ( pid, pcmd, proc ) { for ( p in pcmd ) { if (p == pid) { getpp(proc[p], pcmd, proc); if (pid != PID) printf("%s(%s)───", pcmd[pid], pid); } } } NR > 1 { # pid=>cmd pcmd[$2] = $8; # pid=>Parent pproc[$2] = $3; } END { getpp(PID, pcmd, pproc); printf "\n"; system("pstree -p "PID); }'
source share