[erlang-questions] remote spawns and sending messages to the remote PID
Tue Apr 14 13:32:24 CEST 2009
On Mon, Apr 13, 2009 at 10:05 PM, Bernard Duggan <> wrote:
> Hi Jeff,
> The problem's pretty straightforward.
>> Now I spawn the counter on the bar node:
>> ()3> S=spawn('',counter,run,).
> Returns the process ID of the process executing the counter:run function.
> Whereas this:
>> ()5> T=counter:run(5).
> Returns the return value of the counter:run function, which is a process
> spawned from within that function.
> Basically, you're getting confused between the return value of spawn(),
> which is a function that creates a process, and the return value of
> counter:run which is also a function that creates a process. When you
> call spawn('somenode', counter, run, ) it launches a process which
> executes counter:run, which in turn launches another process (by virtue
> of having a further call to spawn() in it). It's the process returned
> by the spawn() /inside/ counter:run() that you want to send the message
> to. Try this instead:
> S = spawn('', counter, counter, [5, 0]).
> That will bypass the extra call to spawn() and give you the PID you
> actually want to send messages to.
Thanks! Light bulb went off with that explanation. Thanks again.
More information about the erlang-questions