Created
September 22, 2012 22:47
-
-
Save jongillies/3768119 to your computer and use it in GitHub Desktop.
Cheesy example of how to do "bash threads" keeping a limit on the number executing at once.
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 | |
# | |
# Credit goes to Pulu! http://www.linkedin.com/pub/pulu-anau/b/5b4/345 | |
# | |
MAX_JOBS=5 | |
function run_process () | |
{ | |
echo "Running Process $1" | |
#echo "Test STDOUT for this job... RUNNING PROCESS $1" > $1.txt | |
sleep 1 | |
} | |
for i in {1..50} | |
do | |
run_process $i & | |
while [ `jobs | wc -l` -ge $MAX_JOBS ] | |
do | |
sleep 1 | |
done | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment