Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ucsd!ucbvax!hplabs!hpda!hpdslab!hp-ptp!jim From: jim@hp-ptp.HP.COM (James_Rogers) Newsgroups: comp.unix.questions Subject: Re: Parent process ID Message-ID: <1730001@hp-ptp.HP.COM> Date: 11 Aug 89 16:00:52 GMT References: <12046@orstcs.CS.ORST.EDU> Organization: HP Pacific Technology Park - Sunnyvale, Ca. Lines: 34 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