5

I am trying to start 16 python scripts in parallel.

I tried to do

for i in {0..15}
    do
    python my_script.py "$i"
    done 

But checking my htop this only runs on one processor. I am guessing that the process are being executed in sequence.

I can of course open a new tab and run a process in each tab, but that seems to be redundant. What is the proper way to do it?

1 Answer 1

7

You're looking for & which will run jobs in the background:

for i in {0..15}
do
    python my_script.py "$i" &
done

That will launch all 15 simultaneously. Alternatively, for more fine grained control, you might want to check out GNU parallel.

For more information on the various shell control operators, see here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .