Skip to content

Instantly share code, notes, and snippets.

@nuada
Created January 13, 2015 10:24
Show Gist options
  • Select an option

  • Save nuada/a695db9ba9be201ecb23 to your computer and use it in GitHub Desktop.

Select an option

Save nuada/a695db9ba9be201ecb23 to your computer and use it in GitHub Desktop.
#!/bin/bash
max_jobs=4
for i in $(seq 10); do
while [[ $(jobs | wc --lines) -ge ${max_jobs} ]]; do
sleep 1
done
# Do the job
(
echo "Job $i"
sleep $(((RANDOM % 5)+1))
echo "Job $i done"
) &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment