[erlang-questions] spawning processes

Pablo Vieytes pablo.vb80@REDACTED
Thu Aug 2 10:48:04 CEST 2012


Hi,
I tried that but I had problems using self(). I have to communicate the
spawned process with other pocesses, so I need to know the pid of the
spawned process.

This DOESN'T work ->

parent() ->
     Args = data,
     spawn(fun() -> son(Args) end).

son(Args) ->
    %%some code -> NewData
     ReplyTo = self(),
     AnotherProcess ! {ReplyTo, NewData}.

ReplyTo has the pid of process who is running parent fun and I want the pid
of the new process spawned with the son fun.


This WORKS but I have to export the son fun.

parent() ->
     Args = data,
     spawn(?MODULE, son, [Args]).


son(Args) ->
    %%some code -> NewData
     ReplyTo = self(),
     AnotherProcess ! {ReplyTo, NewData}.










2012/8/2 Vlad Dumitrescu <vladdu55@REDACTED>

> Hi and welcome!
>
> On Thu, Aug 2, 2012 at 10:00 AM, Pablo Vieytes <pablo.vb80@REDACTED>
> wrote:
> > I don't know how to spawn a process with args without export it. is there
> > any way to do that?
> >
> > For funs without args  you can do spawn(fun_in_the_same_mod/0). Another
> > option is to use spawn(Module, Function, Args) but  Function should be
> > exported although it's in the same mod.
>
> Try spawn(fun() -> Function(Args) end)
>
> regards,
> Vlad
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120802/89863029/attachment.htm>


More information about the erlang-questions mailing list