$ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the sub- shell.
$ ps -ax | grep bash | grep -v grep 344 p1 Ss 0:00.09 -bash $ echo $$ 344