Created
July 6, 2012 20:11
-
-
Save jelder/3062524 to your computer and use it in GitHub Desktop.
Example of managing lots of background jobs from Bash
This file contains hidden or 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 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