title: Detect end of process from a sub-shell in ksh
body: <p>I launch a master script : master.ksh</p>
  
  <p>I want to do some background task during the work of master.ksh.
  For this, I created an script sourced at the beggining of master.ksh : slave.ksh with a $ </p>
  
  <pre><code>./slave.ksh &amp;
  </code></pre>
  
  <p>here is the code of slave.ksh: </p>
  
  <pre><code>#!/bin/ksh
  
  touch tmpfile
  export thepid=$!
  while [[`if [ -n "$thepid" ];fi`]]; do
      pwd &gt;&gt; tmpfile
      #other set of commands ...
      export thepid=$!
  done
  </code></pre>
  
  <p>thepid is used to monitor the pid of the master.ksh, when master.ksh ends, I expect the end of the slave.ksh too and so, the exit of slave.ksh too</p>
  
  <p>but I get an error from slave.ksh :</p>
  
  <pre><code>syntax error at line 5; fi unexpected
  </code></pre>
  
  <p>if I delete fi , I get another error. What is the good way to test $thepid ?</p>