Created
December 12, 2018 22:28
-
-
Save samredai/cbad746c4e5375c4ad96ae3759c20cd8 to your computer and use it in GitHub Desktop.
Linux: Run Shell commands in parallel
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 | |
for cmd in "$@"; do { | |
echo "Process \"$cmd\" started..."; | |
$cmd & pid=$! | |
PID_LIST+=" $pid"; | |
} done | |
trap "kill $PID_LIST" SIGINT | |
echo "Parallel processes have begun..."; | |
wait $PID_LIST | |
echo | |
echo "Parallel processes have finished!"; | |
#to use this, run './parallel "command1" "command2" "command3"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment