First, create a wrapper script that changes to the directory given in the first (and only) command-line argument, performs whatever setup/variable-initialisation/etc it needs, and then runs your 10 scripts in sequence with whatever args they need.
For example, if each script processes all .jpg, .png, and .gif files
in the directory:
find to pipe a list of directories into
find /path/to/parent/ -mindepth 1 -type -d -print0 |
parallel -0 -n 1 ./example-wrapper.sh
-mindepth 1 option in
find excludes the top level directory, i.e. the parent directory itself)
By default, parallel will run one instance (a "job") of
./example-wrapper.sh for each CPU core you have. Each instance will get ONE (
-n 1) directory name. As soon as a job has finished, another is started (if there are any remaining jobs to run).
This makes maximal use of available CPU power, without letting jobs compete with each other for CPU time.
You can use
-j option to tune the number of jobs to run at once. For CPU-intensive tasks, the default of one job per system core is probably what you want.
If your jobs aren't very CPU-intensive but tend to be more I/O bound, you may want to run 2 or 3 jobs for every core you have (depending on how large your input files are, how fast your storage is, and what kind of devices make up that storage - e.g. SSDs don't suffer from seek latency so won't be slowed down by multiple processes seeking data from all over the disk. Hard disks do suffer from seek times and WILL slow down from being made to seek randomly all over the place - Linux's disk buffering/caching will help, but won't eliminate the problem).
If you want to get other work done (e.g. normal desktop usage) while these jobs are running, use
-j to tell
parallel to use one or two fewer cores than your system has (e.g.
-j 6 on an 8-core system).
NOTE: Tuning parallel processes is a fine art and can take some experimenting to get the best results.
Number of jobslots. Run up to N jobs in parallel. 0 means as many as possible. Default is 100% which will run one job per CPU core.
--semaphore is set default is 1 thus making a mutex.
This is really basic and primitive use of
parallel. It can do a lot more. See the man page for details.
xargs also has a
-P option for running jobs in parallel. For simple usage like this, it makes little difference whether you use
xargs -P or
parallel. But if your requirements are more complicated, use
parallel should be packaged for most linux distros, otherwise it's available from https://www.gnu.org/software/parallel/