[erlang-questions] What's the difference between spawn(Node, Module, Fun, Args) and rpc:call(Node, Module, Fun, Args)?

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Fri Apr 22 12:08:58 CEST 2011

On Fri, Apr 22, 2011 at 12:02, Barco You <barcojie@REDACTED> wrote:
> I'm baffled to distinguish these two usages of RPC and don't know when
> should use which. I appreciate your explanations!

spawn starts off another process that then acts on its own.

rpc:call/4 evaluates a function on another node, but afterwards it
returns the result of that function. There is no new process
afterwards. If you look at the return from rpc:call/4, you see:

       call(Node, Module, Function, Args) -> Res | {badrpc, Reason}

where 'Res' is a term() - the result of apply(Module, Function, Args). Spawn:

      spawn(Node, Module, Function, Args) -> pid()

returns a process identifier for the newly spawned function.
rpc:call/4 is implemented with spawn however, so that might be what is
confusing you.


More information about the erlang-questions mailing list