The basic task I need to do is call a python script multiple times, each time with a different argument. For example:
script.py -t command1
script.py -t command2
script.py -t command3
Etc. Now the problem is that script.py takes a long time to run, so just putting the above in a shell script and running them in series (one after another) is a waste of time.
Instead what I’d like to be able to do is open up multiple terminals, and in each one, run
script.py -t command_i
For the ith command argument. Is there any way of doing this? If not, are there any other helpful parallel options for what I’m trying to do?
Cheers
EDIT – just realized: I probably want some sort of forking, yes? I’ve never done that with shell scripting though.
To run a command in the background, add an
&at the end:If you are using this in a shell script and want to wait for all the processes to finish, run
waitwithout arguments. It will wait for all background jobs in the current shell to complete before continuing the script.