Path: utzoo!attcan!uunet!lll-winken!csd4.milw.wisc.edu!bionet!ames!haven!adm!xadmx!rbj@dsys.icst.nbs.gov From: rbj@dsys.icst.nbs.gov (Root Boy Jim) Newsgroups: comp.unix.wizards Subject: shell script puzzler Message-ID: <19668@adm.BRL.MIL> Date: 18 May 89 16:01:46 GMT Sender: news@adm.BRL.MIL Lines: 33 ? From: Chris Torek ? In article <995@etnibsd.UUCP> vsh@etnibsd.UUCP (Steve Harris) writes: ? >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). I'm running SunOS 3.5. ? >#! /bin/sh ? >echo $$ # echos pid of parent shell ? >( echo $$ ) # echos same pid ? At least in 4BSD, you cannot. `sh' sets up `$$' near the top of main() ? and never changes it (except when running a script, in lieu of starting ? a new /bin/sh to run it). ? -- ? In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) ? Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris Chris hinted that you must run another sh. Here's how: #! /bin/sh echo shell pid $$ (sh -c 'echo subshell pid $$') (echo 'echo another subshell pid $$' | sh) (eval 'echo why is $$ the parent pid?') echo shell pid $$ For some reason, the eval form doesn't work. Root Boy Jim is what I am Are you what you are or what?