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

Michael Turner <>
Fri Sep 7 06:16:18 CEST 2012


On Fri, Sep 7, 2012 at 1:10 PM, Xiao Jia <> wrote:
> 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.

I'm actually having a little trouble with that supposition. Even basic
UNIX split doesn't produce "identical processes" - for example, one
process has knowledge that it's the designated parent, the other that
it's the designated child.

What actual real-world problem are you trying to solve? Maybe Erlang
already does it in a better way.

-michael turner

> 2012/9/7 Rich Neswold <>
>>
>> On Thu, Sep 6, 2012 at 8:31 PM, Xiao Jia <> 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
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Regards,
Michael Turner
Project Persephone
1-25-33 Takadanobaba
Shinjuku-ku Tokyo 169-0075
(+81) 90-5203-8682

http://www.projectpersephone.org/

"Love does not consist in gazing at each other, but in looking outward
together in the same direction." -- Antoine de Saint-Exupéry



More information about the erlang-questions mailing list