[erlang-questions] Parents always take children with them?
Sat Apr 28 23:51:31 CEST 2007
Basically there is no inherent process tree, all processes are created
equal. So even the terminology parent/child process does not apply. The
creating process knows of the created process through the return value
from spawn while the created process has no per default knowledge of who
created it. This you have to pass down either through an argument to
spawn or by sending it a message.
Similarly you have to explicitly set up which processes are linked
together using link/spawn_link. It is through links groups of processes
are set up to terminate together or to be informed if another process
has terminated, and why. An alternative is use monitor. Links are
bidirectional while monitor only goes in one direction.
In your case you could probably have the "parent" process monitor all
its "children" and when all have died terminate itself. You have to
decide how you want to handle errors/fatal termination in the
andrew cooke wrote:
> Do children processes die when the parent finishes (even normally)?
> If so, is there any way to stop this, or do I simply have to arrange that
> the last child is called directly rather than spawned (imagine a parent
> spawning a set of children and then exiting)? Doing this (redirecting the
> parent thread "into" the final child) makes my code less symmetric than I
> would like :o) I would prefer it if a parent could be made to wait for
> all children to terminate (if terminating normally).
> erlang-questions mailing list
More information about the erlang-questions