Parallel Execution with Background Jobs and Limits

Updated

October 31, 2026

Parallel Execution with Background Jobs and Limits

Throttling background jobs to a maximum concurrency pool:

MAX_JOBS=4
for url in "${urls[@]}"; do
    curl -sO "$url" &
    # If pool is full, wait for any one job to complete
    if [[ $(jobs -r -p | wc -l) -ge $MAX_JOBS ]]; then
        wait -n
    fi
done
wait