I know in bash we can create subshells using round parenthesis (
and )
. As per bash man page:
(list) list is executed in a subshell environment
Also to get the current process id we use:
echo $$
Now my question is how to get process id of a subshell created using (
and )
on command line?
If I use this:
echo $$; ( echo $$; )
I will get the parent shell's process id printed twice on stdout since $$
gets expanded even before subshell is created. So how to really force the lazy expansion?
[Solution should work on Mac as well not just Linux]
Update:
Suggested linked answer doesn't work since echo $BASHPID
does not work on my Mac and returns blank.