Suppose I have a bash script that executes code like this:
for i in $LIST; do /path/to/my/script.sh $i & done
As you can see, I am running these scripts in the background and letting the parent script execute as many commands as possible. The problem is that my system will eventually run out of memory, as these commands take about 15 or 20 seconds to start each instance.
I run one static script.sh file and pass a simple variable (i.e. client number) to the script. There are about 20,000 - 40,000 entries that I scroll through at any given time.
My question is how can I tell the system that only the X-number of instances of script.sh is launched immediately. If too many are running, I want to pause the script until the number of scripts is below the threshold and then continues.
Any ideas?
source share