parallel processing - How to increment a variable in parallelized bash script -


so have bash script forks new process in double for-loop

for each date "d":     each instance "i":         do-something "d" "i" &     done done 

and in do-something, increment counter variable. however, since it's counter variable, seems accumulating doesn't work. what's best way solve this?

you can way. what's main reason of incrementing counter in child shell/process when cant value back. incrementing before calling do-something , maintain counter.

#!/bin/bash  c=0 do-something () {  echo 'i shenzi'  sleep 20; }  while : ;     while : ;         echo "-- counter == $((++c))" && sleep 5;         do-something "d" "i"  &     done done 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -