Skip to content

Instantly share code, notes, and snippets.

@jonascheng
Created July 10, 2016 06:02
Show Gist options
  • Save jonascheng/760b410dc59e58586cc23a2b89193bfa to your computer and use it in GitHub Desktop.
Save jonascheng/760b410dc59e58586cc23a2b89193bfa to your computer and use it in GitHub Desktop.
Shell script to concurrent executing the other commands
#!/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