Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to fork/clone a process in Erlang?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Xiao Jia  
View profile  
 More options Sep 6 2012, 9:31 pm
From: Xiao Jia <stfa...@gmail.com>
Date: Fri, 7 Sep 2012 09:31:32 +0800
Local: Thurs, Sep 6 2012 9:31 pm
Subject: Re: [erlang-questions] How to fork/clone a process in Erlang?

Well, this approach can solve much of the problem.
Do you know if there's any approach which can clone the control flow as
well as the states?

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?

2012/9/6 Bengt Kleberg <bengt.kleb...@ericsson.com>

> Greetings,

> Suppose that you have a process running like this:
> loop( State ) ->
>         receive
>         normal ->
>                 New_state = new_state( State ),
>                 loop( New_state )
>         _ -> ok
>         end.

> You could add a forking like this:
> loop( State ) ->
>         receive
>         normal ->
>                 loop( State )
>         fork ->
>                 spawn( fun() -> loop(State) end ),
>                 loop( State )
>         _ -> ok
>         end.

> bengt

> On Thu, 2012-09-06 at 17:02 +0200, Xiao Jia wrote:
> > Hi,

> > How can I fork/clone a process in Erlang, just as the fork in Unix?

> > I have searched a lot but just got nothing related to that. I suppose
> > the usage may look like this:

> > case fork() of
> >   {parent, Pid} -> in_parent_process_now();
> >   {child, Pid} -> in_child_process_now();
> > end.

> > Any ideas?

> > Thanks,

> > Xiao Jia

> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.