-module(newbie). -compile([export_all]). starter() -> Pid = spawn(?MODULE, the_first_p, []), register(pidfirstp, Pid). the_first_p() -> IsPidExists = whereis(pidsecondp), if IsPidExists =:= undefined -> Pid = spawn_link(?MODULE, the_second_p, []), register(pidsecondp, Pid); true -> true end, receive {From, "to first p", Msg} -> From ! {self(), "the_first_p()", Msg} end, the_first_p(). the_second_p() -> IsPidExists = whereis(pidthirdp), if IsPidExists =:= undefined -> Pid = spawn_link(?MODULE, the_third_p, []), register(pidthirdp, Pid); true -> true end, receive {From, "to second p", Msg} -> From ! {self(), "the_second_p()", Msg} end, the_second_p(). the_third_p() -> receive {From, "to third p", Msg} -> From ! {self(), "the_third_p()", Msg} end, the_third_p(). call_the_first() -> pidfirstp ! {self(), "to first p", "Halo first p!"}, receive {Pid, FuncName, Msg} -> {Pid, FuncName, Msg} end. call_the_second() -> pidsecondp ! {self(), "to second p", "Halo second p!"}, receive {Pid, FuncName, Msg} -> {Pid, FuncName, Msg} end. call_the_third() -> pidthirdp ! {self(), "to third p", "Halo third p!"}, receive {Pid, FuncName, Msg} -> {Pid, FuncName, Msg} end.