Created
April 13, 2018 02:07
-
-
Save gugod/af7c91e470857c573c49e5a408fe72cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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