Bobo Bobo - 4 months ago 8
Bash Question

Run in parallel from bash

I have this bash script:

#!/bin/bash
for i in `seq 1 10`;
do
./Hysto file$i.txt
done


I am completely new to parallel programing and even bash language but i meant by this code to run 10 jobs in parallel (I have more than 10 cores available). The program in meant to save data to some files (which don't depend on each other). However in the folder where the files are supposed to be created they appear one by one (the output of file1.txt, then file2.txt and so on), so I assume they are not run in parallel. Can you tell me how can I write a bash file so I can run my jobs in parallel?

Answer

All you need to do to run in parallel in bash is to put an & at the end of your command. Here you'd put it after .txt.

See also: How do you run multiple programs in parallel from a bash script.