Guest User

Untitled

a guest
Dec 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # Global array
  2. declare -a sub_data
  3.  
  4. # A function to increment counter from startCount to endCount
  5. # and save the number in sub_data array
  6. function run_sub()
  7. {
  8. subshellIndex=$1
  9. startCount=$2
  10. endCount=$3
  11. while [ 1 ]
  12. do
  13. startCount=$((startCount + 1))
  14. sub_data[$1]=$startCount
  15. if [ $startCount -ge $endCount ]; then
  16. echo "Coming out $1"
  17. break
  18. fi
  19. sleep 1
  20. done
  21. }
  22.  
  23. function _avg_data()
  24. {
  25. while true
  26. do
  27. local totalValue=0
  28. for indexValue in "${sub_data[@]}"
  29. do
  30. totalValue=$((totalValue + indexValue))
  31. done
  32. echo $totalValue
  33. sleep 4
  34. done
  35. }
  36.  
  37. (run_sub "1" "0" "50")&
  38. pid1=$!
  39. (run_sub "2" "100" "150")&
  40. pid2=$!
  41.  
  42. (_avg_data $sub_data)&
  43. pid3=$!
Add Comment
Please, Sign In to add comment