I hope this is a pseudocode of your actual problem. In that case the problem is that the parent needs to wait till the child has actually installed the handler. This can be achieved by making the parent wait till the child signals it("Telling Hi i am up and ready to go").
have a flag in the parent code as bChildUp. and wait as
while (!bChildUp)
{
// do nothing till the child is up.
}
send a signal from child2 to parent process. The parent process on receiving the signal can change the bChildUp= TRUE. The parent will exit the wait and your task can go on(However you can check if the signal is really from the child2 by getting the pid of the process which sent the signal using siginfo_t and using sigaction to register the signal).
These kind of problems are encountered by
- having a file which the child creates and the parent comes to know that the child is successfully created.
- Or based on signalling mechanism.
I Would suggest to just create a file in the child2 after it is up and let the parent process wait till the file is created.