Spawning multiple threads in Unix

Hi,
I need to spawn mutilpe threads , each invoking a different set of shell scripts, in parallel.
What would be the best way to do that.
Any sample script would greatly help. I am a novice at Unix so any help is much appreciated.

Thanks

Assuming you mean "processes", not "threads" (or don't really care what the difference is, technically speaking), simply run them in the background.

for f in scripts/*; do
  "$f" &
done

will take all the files in the directory scripts and run each in the background.

This isn't a very sophisticated example; if you can elaborate on your requirements, it's easier to give you useful hints.

My requirement is like
I need to call different oracle stored procedures from different set of shell scripts.
I need to run most of them in parallel .

Thanks

a better design / approach would be

( which sometimes may not be the case you are looking for )

have a controller script and it should decide the number of threads to spawn based on throttling, current load, load database that it could with stand and several other factors

also this controller script should receive success / failure message from the instance which it is spawning so that decisions could be taken based on the decision

controller script should be able to collate the results; fluctuate the number of instances running at any point of time..

this might be too much for your requirement, but if you see a pattern of running such tasks in parallel most of the time, this should be a good to go way :slight_smile:

Do you have any example of such script?
:slight_smile:

Using era's example is best imo. It's standard for this type of thing.
If you really need more information before and during execution or find that
forking each shell script is too expensive you could certainly use a glue
language wrapper (Perl/Tcl/Python,etc..) instead of the unix shell and
experiment with these interpreted languages threads.