#!/bin/sh - # # Oliver Fromme # # BSD-style copyright and standard disclaimer applies. # # Trace a process through its parents up till init (PID 1). # If no PID is specified, it starts at your shell's PID. # if [ $# -eq 1 ] && TRACEPID=`expr "$1" : '\([0-9][0-9]*\)$'`; then shift SKIP=0 else TRACEPID=$$ SKIP=1 fi if [ $# -ne 0 ]; then echo "usage: `basename $0` [pid]" >&2 exit 1 fi ps -lwwp 1 | head -1 while :; do if ps -p $TRACEPID >/dev/null; then :; else echo "No such process: $TRACEPID" >&2 exit 1 fi LINE=`ps -lwwp $TRACEPID | tail -1` if [ "$SKIP" != 1 ]; then echo "$LINE" fi SKIP=0 if [ $TRACEPID -lt 2 ]; then break fi TRACEPID=`echo "$LINE" | awk '{print $3 + 0}'` done exit 0 #--