Advertisement
smirnov

spawn.bash

Jun 23rd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.35 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -e
  4.  
  5. declare -ai pids=()
  6.  
  7. ten_seconds() {
  8.         sleep 10s
  9. }
  10.  
  11. twenty_seconds() {
  12.         sleep 20s
  13. }
  14.  
  15. for ((i=0; i < $1; i++)); do ten_seconds & pids+=($!); twenty_seconds & pids+=($!); printf "\rwaiting for %d processes to exit" "$(($i + 1))"; done
  16.  
  17. for p in "${pids[@]}"; do wait -n; printf "done: %d\n" "$p"; done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement