title: Get pid of current subshell
body: <p>I am trying to get the pid of a currently executing subshell - but <code>$$</code> is only returning the parent pid:</p>
  
  <pre><code>#!/usr/bin/sh
  
  x() {
    echo "I am a subshell x echo 1 and my pid is $$"
  }
  
  y() {
    echo "I am a subshell y echo 1 and my pid is $$"
  }
  
  
  echo "I am the parent shell and my pid is $$"
  x &amp;
  echo "Just launched x and the pid is $! "
  
  y &amp;
  echo "Just launched y and the pid is $! "
  
  wait
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>I am the parent shell and my pid is 3107
  Just launched x and the pid is 3108
  I am a subshell x echo 1 and my pid is 3107
  Just launched y and the pid is 3109
  I am a subshell y echo 1 and my pid is 3107
  </code></pre>
  
  <p>As you can see above, when I run <code>$$</code> from the function that I've backgrounded, it does not display the PID as when I do <code>$!</code> from the parent shell.</p>