title: Get the pid and return status from nohup + sudo
body: <p>I have a shell snippet:</p>
  
  <pre><code>nohup sudo node server.js &gt;&gt; node.log 2&gt;&amp;1 &amp;
  
  if [ $? -eq 0 ]; then
    echo $! $?
    echo $! &gt; pids
  fi
  </code></pre>
  
  <p>What I expect is if the <code>node server.js</code> run normaly, then record the pid of this process to the file: pids.</p>
  
  <p>But it does'nt work, the <code>$?</code> is always 0 because it is the status of sudo process?
  And the <code>$!</code> is also not the pid of the process of <code>node</code> command.</p>
  
  <p>So how can I get the correct return code and pid of the <code>node server.js</code> in the above shell script?</p>