I write a script to get data from HDFS parrallel, then I wait for these child processes in a for loop, but sometimes it returns "pid is not a child of this shell". sometimes it works well. It is so puzzled. I use "jobs -l" to show all jobs running in the background. I am sure that these pid is a child process of the shell process, and I use "ps aux" to make sure that these pids are marked with assignment to another process. Here is my script.
PID=() FILE=() let serial=0 while read index_tar do echo $index_tar | grep index > /dev/null 2>&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 \ && mv input/output_$suffix/index_* input/output_$suffix/index & PID[$serial]=$! FILE[$serial]=$index_tar let serial++ done < file.list for((i=0;i<$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
source share