Skip to content

Instantly share code, notes, and snippets.

@jongillies
Created September 22, 2012 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jongillies/3768119 to your computer and use it in GitHub Desktop.
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.
#!/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