How to spawn a process
May 15th, 2009
Erlang is all about processes and their communications. To create a process, we use BIF spawn/3 which returns the new process PID
-module(spawn_process). -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"]), Pid.
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" <0.33.0> 2>