Skip to content
June 13, 2013 / doganay

PID TREE SCRIPT

#!/bin/ksh
#######################################################
## ptree.sh ###########################################
## Mustafa DOGANAY - 2013 #### doganay.wordpress.com ##
#######################################################
if [ $# -ne 1 ]
then
echo "Usage: ptree.sh <pid>"
exit 1
fi
PARENT=$(ps -ef|awk '{if($2=="'$1'") print $3}')
echo $1
echo " "$PARENT
i=2
while [ 1 ]
do
PARENT=$(ps -ef|awk '{if($2=="'$PARENT'") print $3}')
echo $PARENT | awk '{printf "%'$i's%s"," ",$1"\n"}'
if [ X$PARENT == "X0" ]
then
break
fi
((i=i+1))
done
exit 0
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: