The right way to do this in bash depends on whether your chosent test forks to the background or locks stdin.
Most programs will not return the control to the shell until they have finished, unless you explicitly fork them to the background by using the ampersand operator, like in:
If one program locks the shell, then you don't have to do anything special, since the shell script will not continue until the test program has finished.
Code:
for <whatever>
do
# tests and stuff, the script should lock here until this ends
done
If the program doesn't lock or you just want to launch it in the background using '&' so you can do other stuff meanwhile, you can capture the pid, and use it to wait for it later.
Code:
for <whatever>
do
my_test_command&
pid=$! #this catches the pid of the last command
# do anything else if you want
wait $pid #this will lock here until the pid goes away, even if that means hanging forever
done
This has an advantage over pgrep and friends, because pgrep can find any process matching the string you give it. So, you can't guarantee that the correct one is picked if there are many of them running. I generally dislike this kind of approach, as much as I dislike the killall command for similar reasons.