Parent process ID

James_Rogers jim at hp-ptp.HP.COM
Sat Aug 12 02:00:52 AEST 1989


There is no standard variable in the environment, but there is a way to
get what you need.

In ksh you can define the following function which will produce the
information you need:

function ppid {
ps -fp $$ | cut -c15-20 |&
read -p ppid
read -p ppid
echo $ppid
}

This function gets the parent process id from the "ps" comand and then
extracts all the surrounding information.

"ps -fp $$" produces the following line:

     UID   PID  PPID  C    STIME TTY      TIME COMMAND
     jim 27859 27818196 08:55:01 ttyp9    0:03 ps -fp 27859

Piping the above data through "cut -c15-20" produces:

 PPID
27818

Ending the pipe command with "|&" causes the output of the command to be
piped back into the current shell.  The first "read -p ppid" then reads
the first line of data from the pipe.  The second "read -p ppid" reads
the second line of data from the pipe.  Now "ppid" contains the value we
want and we echo that value to stdout.


Jim Rogers at Hewlett Packard



More information about the Comp.unix.questions mailing list