Shell to run one after another checking any flag or file

a.ksh & b.ksh run at the same time and takes huge resource and time.I want to put a technique so that one wil run after another.

eg put a flag so that each script will check if it running , then sleep and wait it to finish.

Can some one advise

touch a file in each script then check that touched file. Keep in mind you could run into a deadlock though. This should give you a general idea of what might be possible.

ie:

script 1

#add code to check for script2.running.

touch script1.running

do work
...

rm script1.running

in script 2

while [[ -e script1.running ]]
do
   echo not yet
   sleep 5
done

touch script2.running

do work
...

rm script2.running

I m trying to do it like below..
syntax is not working
#flag is a paramater whcih will imply that that script will be checked for dependecy .

if ( $FLAG='y' ) then
while [ ! -f flag.running ]
do
sleep 300
done
else
touch flag.running
. ./test.ksh
fi

rm flag.running
.....

The logic is somewhere wrong.. Is there way to set the global env parameters and the script can check the flag and then run