[erlang-questions] How to fork/clone a process in Erlang?

Xiao Jia stfairy@REDACTED
Fri Sep 7 06:10:35 CEST 2012


Well, this is kind of different from what I'm thinking about.

The function g() here is just a symbolic stuff, standing for the remaining
control flows.

Suppose we want to implement a function, split(), which is to create two
identical processes on invocation. We may use fork() inside split(). But
from the user's perspective, he just calls split(). As we write the
split()function, we cannot assume (actually we are unable to know)
what is
g().

2012/9/7 Rich Neswold <rich.neswold@REDACTED>

> On Thu, Sep 6, 2012 at 8:31 PM, Xiao Jia <stfairy@REDACTED> wrote:
> > Of course in your example the control flow is cloned as you also loop in
> the
> > spawn fun.
> > But what I want is a more general case. Take the following C code as an
> > example.
> >
> > f();
> > fork();
> > g();
> >
> > Here the return value of fork() is ignored, so the next steps of both the
> > parent and the child
> > process are the same, which is to execute g(). Can I achieve this in
> Erlang?
>
> How about:
>
> f(),
> spawn(g),
> g().
>
> --
> Rich
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120907/a751eaaa/attachment.htm>


More information about the erlang-questions mailing list