[erlang-questions] A Question About Processes

Dimitar Haralanov <>
Mon Mar 21 22:35:04 CET 2016


Hello everyone!

I am new to Erlang, but I’ve been really enjoying almost every bit of it. I stumbled upon
something I am not exactly sure about. So far, my understanding is that processes are
created by spawn()-ing them, however I think this is not the complete truth. I have the
following contrived example:

-module(foo).
-export([bar/0]).

bar() ->
  io:format("Hello from ~p~n", [self()]),
  spawn(fun loop/0).

loop() ->
  receive
    Message ->
      io:format("PID ~p received ~p~n", [self(), Message]),
      loop()
  end.

and after running the code we get:

1> Pid = foo:bar().
Hello from <0.33.0>
<0.35.0>
2> Pid ! hello.
PID <0.35.0> received hello
hello
3>

My question is - how is the process with PID <0.33.0> spawned? I’ve only read about
using the erlang:spawn() function call, but I guess there are other implicit ways of starting
new processes. Any further clarification would be really helpful. Thank you!

Kind regards,
Dimitar




More information about the erlang-questions mailing list