Skip to content

Instantly share code, notes, and snippets.

@jelder
Created July 6, 2012 20:11
Show Gist options
  • Save jelder/3062524 to your computer and use it in GitHub Desktop.
Save jelder/3062524 to your computer and use it in GitHub Desktop.
Example of managing lots of background jobs from Bash
#!/bin/bash
function my_slow_job() {
sleep 1
}
function parallel_demo() {
count=${1:-10}
echo "Starting $count parallel processes:"
for i in $(seq -w $count) ; do
my_slow_job &
pids="${pids} $!"
done
jobs
for pid in $pids ; do
wait $pid
done
echo "Done!"
}
time parallel_demo 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment