#!/bin/sh - # # Print the given PID, its parent PID etc. up to init's PID. # If no PID is specified, start with the current shell's PID. # Works only with BSD-style "ps" syntax. # # Copyright (C) 1997-2000 Oliver Fromme # Use and distribute under BSD license. # 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 LINE=`ps -lwwp $TRACEPID | tail -1` case "$LINE" in *${TRACEPID}*) ;; *) echo "$0: PID $TRACEPID not found." >&2 exit 1 ;; esac if [ "$SKIP" != 1 ]; then echo "$LINE" fi SKIP=0 if [ $TRACEPID -lt 2 ]; then break fi TRACEPID=`echo "$LINE" | awk '{print $3}'` done #--