Skip to content

Instantly share code, notes, and snippets.

@gugod
Created April 13, 2018 02:07
Show Gist options
  • Save gugod/af7c91e470857c573c49e5a408fe72cd to your computer and use it in GitHub Desktop.
Save gugod/af7c91e470857c573c49e5a408fe72cd to your computer and use it in GitHub Desktop.
#!/bin/bash
function wait_until_job_vacancy() {
local limit=${1:-4}
while [[ ! "$(jobs -p | wc -l)" -lt $limit ]]
do
sleep 1
done
}
function do_one_job {
wait_until_job_vacancy
local delay=$(echo $RANDOM | cut -c 2)
echo "Job delay = $delay"
sleep $delay &
}
while true
do
do_one_job
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment