I have a loop for execution a multitasking job like this:
while read -r dir file; do
cd ./"${dir}"
if [ -r ${dir}-executed.gz ]; then
echo "data already exist."
fi
if ! gunzip -t "${dir}-executed.gz" &> /dev/null ; then
exec-job -i "${file}" -o "${dir}-executed.gz"
else
echo -e "Executed file is Ok. No need further execution"
fi
cd ..
done <./tmp/samples.config
There are 27 files should be executed with exec-job -i "${file}" -o "${dir}-executed.gz".
I want to execute for example 4 jobs by 4 jobs in background using "&" at the end of the job. for example: exec-job -i "${file}" -o "${dir}-executed.gz" &
Therefore, I would like to know that how can I control the number of parallel executions using "&"; not all 27 executions simultaneously.