Created
September 26, 2016 03:03
-
-
Save quantizor/e62d48dc9bfe325859fe409731033ed4 to your computer and use it in GitHub Desktop.
parallelize commands
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 | |
# 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