Many thanks 3run.
proc_status was the key. With this I found another solution (in the manual) and it works for me:
function foo()
{
int i;
for (i=0; i<100; i++) { wait(1); }
}
...
foo();
wait_for(foo); // wait until foo is terminated
Best regards!
Edit: Oh I wrote and dont saw the other answers, sorry xD
Thanks for all answers!