Get pid of current subshell
Modern bash If you are running bash v4 or better, the PID of the subshell is available in $BASHPID. For example: $ echo $$ $BASHPID ; ( echo $$ $BASHPID ) 32326 32326 32326 1519 In the main shell, $BASHPID is the same as $$. In the subshell, it is updated to the subshell’s PID. … Read more