This question already has an answer here:
- $BASHPID And $$ differ in some cases 2 answers
How can I get the pid of a subshell?
$ echo $$ 16808
This doesn't work, because the original shell expands
$ ( echo $$ ) 16808
Why does single quoting not work? After the original shell removes the single quote, does the subshell not expand
$$ in itself?
$ ( echo '$$' ) $$
eval not work either? Is
eval run by the subshell? Why does it give me the original shell's PID?
$ ( eval echo '$$' ) 16808