job/process scheduling or control

Hi forum,

I have a problem concerning job or process scheduling and control.

I have to run 24 jobs (could be more sometimes less) of the same programme with different parameters. The machine this code is running on is an 8-core machine, so I was thinking that running all the processes at once would not be such a good idea because it would cause throttling between processes and some overhead. I could be wrong on this, feel free to correct me...

However, I don't seem to get my head around a way to control my batch of jobs/processes so that only 8 and always 8 processes are running (except at the end of the batch ofcourse).

in pseudocode it would have to look something like

for i in 1 to 24
x = get nr of jobs
while x < 8
start job i
done
done

however this stops if 7 jobs are reached. The while loop should be have a part that polls for the number of jobs and updates x, and re-enters the for loop if the condition is not met instead of exiting both the while and for loop.

Any pointers, ideas?