title: bash setsid nohup ./prog & -- $! not pointed at child process
body: <p>I was trying to get pid of process I ran with <code>setsid</code> and which ought to run in background like this:</p>
  
  <pre><code>test.sh:
  
  #/bin/bash
  setsid nohup ./my_program &amp;
  echo $!
  </code></pre>
  
  <p>if I run <code>./test.sh</code> it will print a pid of <code>my_program</code> process and it's exactly what I need. But if run this commands one by one in my shell like this:</p>
  
  <pre><code>$ setsid nohup ./my_program &amp;
  $ echo $!
  </code></pre>
  
  <p>It will give me a pid of <code>setsid</code> command (or may be something else, but it almost all times gives me pid of <code>my_program</code> minus one).</p>
  
  <p>What is happening here? Why results of commands I ran in terminal by myself differs from results of <code>test.sh</code> script?</p>
  
  <p>Btw, may be you know some easy way of process which I started with setsid and which I need to run in background?</p>