title: Parent process didn't exit while using cd xxx && nohup sh xx.sh &
body: <p>I've met this weird issue last night but still have no clue about it. Here's the thing:</p>
  
  <p>I got 2 processes named <code>parent.sh</code> and <code>child.sh</code>, and it's supposed to be <code>parent.sh</code> start the <code>child.sh</code>, and then <code>parent.sh</code> exits while <code>child.sh</code> still run. (<code>parent.sh</code> is just like <code>apachectl</code> or anything in <code>/etc/init.d/xxx</code></p>
  
  <p>code in <code>parent.sh</code></p>
  
  <pre><code>#!/bin/bash
  
  echo 'start child.sh'
  cd $HOME &amp;&amp; nohup sh child.sh &amp;
  </code></pre>
  
  <p>code in <code>child.sh</code></p>
  
  <pre><code>#!/bin/bash
  
  while true;
  do
      echo 'child process';
      sleep 10
  done
  </code></pre>
  
  <p>After I run <code>sh parent.sh</code>, it seems like the <code>parent.sh</code> has exit cause I got the bash. Unfortunately when I do <code>ps -ef | grep parent.sh</code> , it's still there with a parent process <code>init</code>, and the child process <code>child.sh</code> is also running.</p>
  
  <p>After some check for <code>parent.sh</code>, I found that if I change this line:</p>
  
  <pre><code>cd $HOME &amp;&amp; nohup sh child.sh &amp;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>cd $HOME; nohup sh child.sh &amp;
  </code></pre>
  
  <p>then the parent process will exit after it start the child process.</p>
  
  <p>Why?</p>