[erlang-questions] A Question About Processes

Felix Gallo felixgallo@REDACTED
Mon Mar 21 23:16:06 CET 2016


<0.33.0> was spawned when you started the interactive shell.  self() is the
pid of the process which is performing the function call, which in this
case is the interactive shell itself.

You can test this:

Eshell V7.2.1  (abort with ^G)

1> c(foo),l(foo),foo:bar().

Hello from <0.34.0>

<0.40.0>

2> self().

<0.34.0>

3>

On Mon, Mar 21, 2016 at 2:35 PM, Dimitar Haralanov <dharalanov@REDACTED>
wrote:

> 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
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160321/671e88e7/attachment.htm>


More information about the erlang-questions mailing list