title: wait child process but get error: 'pid is not a child of this shell'
body: <p>I write a script to get data from HDFS parrallel，then I wait these child processes in a for loop, but sometimes it returns "pid is not a child of this shell". sometimes, it works well。It's so puzzled. I use "jobs -l" to show all the jobs run in the background. I am sure these pid is the child process of the shell process, and I use "ps aux" to make sure these pids is note assign to other process. Here is my script.</p>
  
  <pre><code>PID=()
  FILE=()
  let serial=0
  
  while read index_tar
  do
          echo $index_tar | grep index &gt; /dev/null 2&gt;&amp;1
  
          if [[ $? -ne 0 ]]
          then
                  continue
          fi
  
          suffix=`printf '%03d' $serial`
          mkdir input/output_$suffix
          $HADOOP_HOME/bin/hadoop fs -cat $index_tar | tar zxf - -C input/output_$suffix \
                  &amp;&amp; mv input/output_$suffix/index_* input/output_$suffix/index &amp;
  
          PID[$serial]=$!
          FILE[$serial]=$index_tar
  
          let serial++
  
  done &lt; file.list
  
  for((i=0;i&lt;$serial;i++))
  do
          wait ${PID[$i]}
  
          if [[ $? -ne 0 ]]
          then
                  LOG "get ${FILE[$i]} failed, PID:${PID[$i]}"
                  exit -1
          else
                  LOG "get ${FILE[$i]} success, PID:${PID[$i]}"
          fi
  done
  </code></pre>