Tried to implement simple barrier in linux shell but fail
Posted: Mon Sep 21, 2020 7:38 pm
I think I am doing something wrong when I tried to implement simple barrier in linux shell script but seem to fail spectacularly.
The problem is I can see <snippet1> and all instances of <script1> is launched
But output of code block in <snippet2> appearing before the output of instances of <script1>.
Because there is a dependency where <script1> can not run after <snippet2> is executed it runs into all sort of errors.
Code: Select all
# some code block before launching scripts in parallel.
<snippet1>
...
for loop
# should launch instances of each script1 in background since ampersand implied.
launch another shell script in <script1> in background &
done
#barrier implementation, wait loop until all instances of script1 finished running.
for loop
count=`ps -ef | grep <script1> | wc -l`
if count -eq 0
break
fi
done
...
# some code block after launching scripts in parallel.
<snippet2>
But output of code block in <snippet2> appearing before the output of instances of <script1>.
Because there is a dependency where <script1> can not run after <snippet2> is executed it runs into all sort of errors.