[erlang-questions] Erlang shell, process dictionary & rand:seed

Robert Virding rvirding@REDACTED
Fri Jan 13 15:55:54 CET 2017


Not quite, it is really 3 processes: a "master" process which keeps track
of the others; an evaluator process which does all the work; and a process
which reads the inputs. It is the evaluator process which crashes when
there is an error and it is the one which receives messages and is linked.
The shell master does not keep track of the evaluator's links so when it
dies they all go away.

Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:8:8]
[async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.0  (abort with ^G)
1> self().
<0.57.0>
2> process_info(self(), links).
{links,[<0.51.0>]}
3> link(whereis(error_logger)).
true
4> process_info(self(), links).
{links,[<0.51.0>,<0.30.0>]}
5> exit(die_die_die).
** exception exit: die_die_die
6> self().
<0.63.0>
7> process_info(self(), links).
{links,[<0.51.0>]}
8> link(whereis(error_logger)).
true
9> process_info(self(), links).
{links,[<0.51.0>,<0.30.0>]}
10> exit(normal).
** exception exit: normal
11> self().
<0.69.0>
12> process_info(self(), links).
{links,[<0.51.0>]}
13>

But yes, the shell master keeps track of the process dictionary and the
variable bindings and passes them on to the next evaluator process.

The evaluator process does nothing special to catch errors and quite
happily just dies when there is an error as it knows the master process
will handle. It's the "let it crash" philosophy even here.

Robert


On 12 January 2017 at 13:43, Raimo Niskanen <
raimo+erlang-questions@REDACTED> wrote:

> On Thu, Jan 12, 2017 at 09:58:06AM +0000, Roger Lipscombe wrote:
> > On 12 January 2017 at 08:41, Raimo Niskanen
> > <raimo+erlang-questions@REDACTED> wrote:
> > > It is a shell feature.
> > >
> > > Notice below - an "** exception error:" is different from
> > > "*** Shell process terminated! ***".  1/0 is as well as most other
> > > exceptions is caught by the evaluator so the process will not exit.
> >
> > Except that the process *does* exit (note that my shell displays the
> > pid in the prompt, but I've added self() calls to be clear):
> >
> > Erlang/OTP 17 [erts-6.4.1.2] [source-73fc7ca] [64-bit] [smp:12:12]
> > [async-threads:10] [hipe] [kernel-poll:false]
> >
> > Eshell V6.4.1.2  (abort with ^G)
> > <0.33.0> 1> self().
> > <0.33.0>
> > <0.33.0> 2> put(a, 1).
> > undefined
> > <0.33.0> 3> get().
> > [{a,1}]
> > <0.33.0> 4> 1/0.
> > ** exception error: an error occurred when evaluating an arithmetic
> expression
> >      in operator  '/'/2
> >         called as 1 / 0
> > <0.38.0> 5> self().
> > <0.38.0>
> > <0.38.0> 6> get().
> > [{a,1}]
>
> Well, how about that!?
>
> The shell does strange things.  It is for example divided into two
> processes; one evaluator process and one other process that I think for
> instance owns links, receives messages, etc.
>
> It seems the shell emulates what I said i.e that an exception was caught,
> but the process receiving messages actually died due to the exception.
>
> Confusing.  I wonder if it is possible to correct...?
>
> Nevertheless, if a non-emulated process dies due to a runtime error e.g
> division by zero, its process dictionary, links and other process stuff
> dies with it.
>
> --
>
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
> _______________________________________________
> 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/20170113/e2987d36/attachment.htm>


More information about the erlang-questions mailing list