Getting PID of a Sub-Shell

From: Crist Clark (Crist.Clark@globalstar.com)
Date: Thu Feb 28 2008 - 17:36:01 EST


I've got a ksh script where I'd like to learn the PID of
a sub-shell within the sub-shell code.

If you have code like,

        $ cat pidtest.sh
        /bin/echo "$$"
        ( /bin/echo "$$" )
        $ ksh pidtest.sh
      29586
      29586

You'll see the same number even though the second echo runs
in a sub-shell with a different PID. If I run the script
in truss(1) I do see that it is indeed happening as I expect
it would, but the "$$" does not get changed when the sub-shell
gets fork(2)ed off.

Bug or feature?

Anyway, anyone know of a way to work around it? How do I get
the PID of that sub-shell from code within the sub-shell?

BB<information contained in this e-mail message is confidential, intended
only for the use of the individual or entity named above. If the reader
of this e-mail is not the intended recipient, or the employee or agent
responsible to deliver it to the intended recipient, you are hereby
notified that any review, dissemination, distribution or copying of this
communication is strictly prohibited. If you have received this e-mail
in error, please contact postmaster@globalstar.com
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:42:48 EDT