1

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.

  • 2
    Sounds like perhaps you should use a tool like [GNU `parallel`](http://www.gnu.org/software/parallel/) rather than trying to reinvent this by hand. – Nate Eldredge Mar 18 '16 at 16:30

0 Answers0