Thu, 14 Jul 2005, Dave Anderson wrote:
It also, at least under BSD, has the serious problem that "$$"
isn't the PID of the shell running the script but rather the PID of the
"original" shell (whatever exactly that means; some testing suggests
that it's the last process on the PPID chain which is still in this
process group) and I haven't yet found any straightforward way of
getting the PID of the "bottom-level" shell, which is what is needed
for the stale-lock testing to work at all when the exclusion needed is
among scripts run in subshells of the same shell. (I realize that I
could create a trivial program which writes its PPID to stdout, or hack
/bin/sh to add a new variable which contains the PID I want -- but I'd
prefer to use the tools which come as part of the base system. This
has also left me rather curious as to *why* the PID and PPID of the
"original" shell are easily accessible in scripts but those of the
subshell actually running the script aren't.)
I did not check your script, but PSIX says this:
$ Expands to the decimal process ID of the invoked shell. In a
subshell (see Shell Execution Environment ), '$' shall expand to the
same value as that of the current shell.
There's a similar phrase in the man page,