Skip to content

Instantly share code, notes, and snippets.

@quantizor
Created September 26, 2016 03:03
Show Gist options
  • Save quantizor/e62d48dc9bfe325859fe409731033ed4 to your computer and use it in GitHub Desktop.
Save quantizor/e62d48dc9bfe325859fe409731033ed4 to your computer and use it in GitHub Desktop.
parallelize commands
#!/bin/bash
# adapted from http://stackoverflow.com/questions/10909685/run-parallel-multiple-commands-at-once-in-the-same-terminal
# but this version works in Ubuntu + Windows Subsystem for Linux
PID_LIST=""
for cmd in "$@"; do {
echo "Process \"$cmd\" started";
eval $cmd & pid=$!
PID_LIST="$PID_LIST $pid";
} done
trap "kill $PID_LIST" INT
echo "Parallel processes have started";
wait $PID_LIST
echo
echo "All processes have completed";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment