Skip to content

Instantly share code, notes, and snippets.

@originalsouth
Last active May 17, 2017 09:18
Show Gist options
  • Save originalsouth/cc07accac85bed4e3443547c694ee4a1 to your computer and use it in GitHub Desktop.
Save originalsouth/cc07accac85bed4e3443547c694ee4a1 to your computer and use it in GitHub Desktop.
Launch a bunch of tasks concurrently
#!/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
@originalsouth
Copy link
Author

Typing TASKS=10 CONCURRENCY=1 ./cm.zsh echo into the command line should get you started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment