fork(){
i=0
count=0
while (($count<5))
do
fpfunction &
pid=$!
#Ensure the pid is available
if [ -z "$pid" ]; then
echo "IS NULL"
else
Array[$i]=$pid
echo "PID is $pid"
fi
wait [$pid]
i=$((i+1))
count=$(( count+1 ))
done
echo "PID: ${Array[*]}"
}
The fpfunction() only echo a string, so I dont write it here.
My understanding to wait() is it will wait a child process to complete and then return a value.
I put wait() in my script because I want to ensure all child processes are finished.
However, the error occured
not a pid or valid job spec
Is my understanding wrong? please let me know how to fix this issue.
Thanks a lot.
fpfunctionto start a sub-process and wait for it. If You want to limit the number of process started I suggest to usemake.