Last active
May 17, 2017 09:18
-
-
Save originalsouth/cc07accac85bed4e3443547c694ee4a1 to your computer and use it in GitHub Desktop.
Launch a bunch of tasks concurrently
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/env zsh | |
TASKS="${TASKS:=100}" | |
CONCURRENCY="${CONCURRENCY:=8}" | |
main() | |
{ | |
for t in `seq $TASKS` | |
do | |
$@ $t & | |
while [ $(ps --no-headers -o pid --ppid=$$ | wc -w) -gt $CONCURRENCY ] | |
do | |
sleep 1 | |
done | |
done | |
} | |
if [ $# -eq 0 ] | |
then | |
echo "cm: to what do I owe the extreme pleasure of this visit?" | |
else | |
main $@ | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typing
TASKS=10 CONCURRENCY=1 ./cm.zsh echo
into the command line should get you started.