Home > Basic > How to spawn a process

How to spawn a process

Erlang is all about processes and their communications. To create a process, we use BIF spawn/3 which returns the new process PID

-export([do_spawn/0, call/2]).

call(Arg1, Arg2) ->
    io:format("~p ~p~n", [Arg1, Arg2]).

do_spawn() ->
    %% Equivalent to SpawnProcess:call("hello", "process"),
    Pid = spawn(?MODULE, call, ["hello", "process"]),

Output of the call spawn_process:do_spawn/0 is the Pid of the newly created process. ?MODULE is the macro refers to the current module

1> spawn_process:do_spawn().
"hello" "process"

Basic , , ,

  1. No comments yet.
  1. No trackbacks yet.