title: How can I get both the process id and the exit code from a bash script?
body: <p>I need a bash script that does the following:</p>
  
  <ul>
  <li>Starts a background process with all output directed to a file</li>
  <li>Writes the process's exit code to a file</li>
  <li>Returns the process's pid (right away, not when process exits).</li>
  <li>The script must exit</li>
  </ul>
  
  <p>I can get the pid but not the exit code:</p>
  
  <pre><code>$ executable &gt;&gt;$log 2&gt;&amp;1 &amp;
  pid=`jobs -p`
  </code></pre>
  
  <p>Or, I can capture the exit code but not the pid:</p>
  
  <pre><code>$ executable &gt;&gt;$log;
  # blocked on previous line until process exits
  echo $0 &gt;&gt;$log;
  </code></pre>
  
  <p>How can I do all of these at the same time?</p>