Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!hc!lll-winken!uunet!etnibsd!vsh From: vsh@etnibsd.UUCP (Steve Harris) Newsgroups: comp.unix.wizards Subject: shell script puzzler Keywords: /bin/sh Message-ID: <995@etnibsd.UUCP> Date: 20 Mar 89 17:34:09 GMT Organization: Eaton Ion Beam Systems Div., Beverly, MA Lines: 22 Here is one for the shell programming gurus: given the following shell script, how can I get the subshell to echo its true pid?? (I am running SunOS 3.4, if it matters). =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #! /bin/sh echo $$ # echos pid of parent shell ( echo $$ ) # echos same pid =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- I assume that when the shell encounters the ( list ) construction it simply forks a copy of itself, with input limited to the list, perhaps with I/O redirected, but with all variables preserved. In particular, the variable $$ seems to be preserved. Is this assumption correct? Using this construction (i.e., not replacing it with a here-document, etc.), is there any SIMPLE way to get the pid of the subshell? PS -- this puzzler is just for your entertainment, I have plenty of work-arounds. -- Steve Harris -- Eaton Corp. -- Beverly, MA -- uunet!etnibsd!vsh