Process waiting problem.

Process waiting problem.

Post by Nigel Fole » Wed, 29 Jan 1997 04:00:00



Hello,

I have a parent process which starts a child process.
This child process then kicks off some children of its own in the
background and then terminates.

I need the parent process to wait until all grandchildren
are dead but the wait() will only hold until the child terminates
and not the grandchildren.

Any Ideas?
Nigel Foley.

 
 
 

Process waiting problem.

Post by Joe Halp » Wed, 29 Jan 1997 04:00:00



>Hello,

>I have a parent process which starts a child process.
>This child process then kicks off some children of its own in the
>background and then terminates.

>I need the parent process to wait until all grandchildren
>are dead but the wait() will only hold until the child terminates
>and not the grandchildren.

>Any Ideas?
>Nigel Foley.

Have the child process wait() for the grandchildren, and only exit
after they're gone.

Joe

 
 
 

Process waiting problem.

Post by Michel Prévos » Thu, 30 Jan 1997 04:00:00



> Hello,

> I have a parent process which starts a child process.
> This child process then kicks off some children of its own in the
> background and then terminates.

> I need the parent process to wait until all grandchildren
> are dead but the wait() will only hold until the child terminates
> and not the grandchildren.

> Any Ideas?
> Nigel Foley.

What I think is that the grandchildren become orphans. That is, their
parent dies, so they become inherited by init, whose pid is 1.

Maybe you should make the first child wait for its own children, then
make it terminate after all of the children have died. I have seen in
a book that a common way for a parent that is not interested in the
termination status of its children is to fork twice, i.e. the parent
forks, wait for its child to terminate, then continue processing of
its own. After the fork, the child forks again, then terminates, its
child, the grandchildren of the parent, being orphaned and inherited
by init.

Hope this helps.

Michel