Get pid of current subshell

后端 未结 6 799
眼角桃花
眼角桃花 2020-12-08 07:10

I am trying to get the pid of a currently executing subshell - but $$ is only returning the parent pid:

#!/usr/bin/sh

x() {
  echo \"I am a sub         


        
6条回答
  •  一生所求
    2020-12-08 07:30

    It's better to use $(exec sh -c 'echo $PPID') rather than tricks shown in answer by John1024 (those tricks not work witn modern shells at present time, when I writing my reply).

    See this question: https://unix.stackexchange.com/questions/484442/how-can-i-get-the-pid-of-a-subshell

提交回复
热议问题