Created
July 10, 2016 06:02
-
-
Save jonascheng/760b410dc59e58586cc23a2b89193bfa to your computer and use it in GitHub Desktop.
Shell script to concurrent executing the other commands
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/sh | |
# ex: ./parallel_commands.sh 'echo test' 'echo test' | |
for cmd in "$@"; do { | |
echo "Process \"$cmd\" started"; | |
$cmd & pid=$! | |
PID_LIST+=" $pid"; | |
} done | |
trap "kill $PID_LIST" SIGINT | |
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