I know I can get process id of the main shell by $$, but how do you get PID of subshell created by e.g. ( ... ) from within the block?
Asked
Active
Viewed 291 times
1 Answers
1
You can use $BASHPID, to see the difference :
(echo $$ $BASHPID)
Philippe
- 1,275
- 7
- 14
-
That seems to work in Bash, I also wonder, how can you do it in POSIX shell? – jarno Mar 18 '20 at 18:19
-
1`(pid=$(exec sh -c 'echo "$PPID"'); echo "$$ $pid")`. See https://unix.stackexchange.com/a/484464/40484 – Paulo Tomé Mar 18 '20 at 18:25