willyb321

parallel_commands

Aug 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.25 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. for cmd in "$@"; do {
  4.   echo "Process \"$cmd\" started";
  5.   $cmd & pid=$!
  6.   PID_LIST+=" $pid";
  7. } done
  8.  
  9. trap "kill $PID_LIST" SIGINT
  10.  
  11. echo "Parallel processes have started";
  12.  
  13. wait $PID_LIST
  14.  
  15. echo
  16. echo "All processes have completed";
Advertisement
Add Comment
Please, Sign In to add comment