#!/bin/ksh #Trace the ancestry of the given PID: Handout 6, pp. 2-3. if [[ $# -ne 1 ]] then echo $0: arg must be PID 1>&2 exit 1 fi ps -Af | awk ' NR == 1 {print} NR > 1 { line[$2] = $0 #$2 is PID parent[$2] = $3 #$3 is PPID } END { for (pid = '$1';; pid = parent[pid]) { if (line[pid] == "") { print "'$0': PID " pid " not found" exit 2 } print line[pid] if (pid == parent[pid]) { #reached the top exit 0 } } } '