Quantcast

Shell pid changes after an error occurred

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Shell pid changes after an error occurred

Jakub Groncki
Hi,

My first message here so it may be very n00b but well, I just started to pick up some Erlang a couple of days ago (I'm halfway through "Introducing Erlang" + I find this book quite enjoyable). So there's this one thing that's been bugging me ever since I learnt about processes, pids and the like - the shell pid seems to change after an error caused by malformed code or after a user exception is thrown. See this terminal session snippet:

Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.3  (abort with ^G)
1> self().
<0.58.0>
2> error(sadface).
** exception error: sadface
3> self().
<0.61.0>

So here you can see self() yields different values. Does anybody know why it happens the way it happens?

PS Of course I'm not implying there's something wrong with this kind of behavior but still it's really interesting.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell pid changes after an error occurred

Loïc Hoguin-3
Before running your error command, try:

catch_exception(true).

http://erlang.org/doc/man/shell.html#catch_exception-1

On 04/09/2017 09:46 PM, Jakub Groncki wrote:

> Hi,
>
> My first message here so it may be very n00b but well, I just started to
> pick up some Erlang a couple of days ago (I'm halfway through
> "Introducing Erlang" + I find this book quite enjoyable). So there's
> this one thing that's been bugging me ever since I learnt about
> processes, pids and the like - the shell pid seems to change after an
> error caused by malformed code or after a user exception is thrown. See
> this terminal session snippet:
>
> Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:2:2] [async-threads:10]
> [hipe] [kernel-poll:false]
>
> Eshell V8.3  (abort with ^G)
> 1> self().
> <0.58.0>
> 2> error(sadface).
> ** exception error: sadface
> 3> self().
> <0.61.0>
>
> So here you can see self() yields different values. Does anybody know
> why it happens the way it happens?
>
> PS Of course I'm not implying there's something wrong with this kind of
> behavior but still it's really interesting.
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell pid changes after an error occurred

Jakub Groncki
Oh wow, this is neat, I would have never guessed, thank you :)

2017-04-09 22:53 GMT+02:00 Loïc Hoguin <[hidden email]>:
Before running your error command, try:

catch_exception(true).

http://erlang.org/doc/man/shell.html#catch_exception-1


On 04/09/2017 09:46 PM, Jakub Groncki wrote:
Hi,

My first message here so it may be very n00b but well, I just started to
pick up some Erlang a couple of days ago (I'm halfway through
"Introducing Erlang" + I find this book quite enjoyable). So there's
this one thing that's been bugging me ever since I learnt about
processes, pids and the like - the shell pid seems to change after an
error caused by malformed code or after a user exception is thrown. See
this terminal session snippet:

Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:2:2] [async-threads:10]
[hipe] [kernel-poll:false]

Eshell V8.3  (abort with ^G)
1> self().
<0.58.0>
2> error(sadface).
** exception error: sadface
3> self().
<0.61.0>

So here you can see self() yields different values. Does anybody know
why it happens the way it happens?

PS Of course I'm not implying there's something wrong with this kind of
behavior but still it's really interesting.


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


--
Loïc Hoguin
https://ninenines.eu


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell pid changes after an error occurred

Richard A. O'Keefe-2
In reply to this post by Loïc Hoguin-3
Reflecting on this, I know *I* was surprised the first time I
realised that exceptions crashed and restarted the shell.
One reason it was surprising was that
1> X = 1.
1
2> Y.
* 1: variable 'Y' is unbound
3> error(goo).
** exception error: goo
4> X.
1
5> Y = self().
<0.37.0>
6> error(cthu).
** exception error: cthu
7> {Y, self()}.
{<0.37.0>,<0.41.0>}

so that "ports and ETS tables as well as processes linked to
the evaluator process" don't "survive the exception" in
contrast to variable bindings, which visibly DO survive.

The case of Y is particularly confusing.

Would it help if restarted shells printed a message
"Shell restarted: associated ports, ETS tables, and links lost."
?


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shell pid changes after an error occurred

Jakub Groncki
I think it would be more than helpful but on the other hand some new users could say that the shell is buggy because it crashes and restarts for no good reason...

2017-04-10 6:48 GMT+02:00 Richard A. O'Keefe <[hidden email]>:
Reflecting on this, I know *I* was surprised the first time I
realised that exceptions crashed and restarted the shell.
One reason it was surprising was that
1> X = 1.
1
2> Y.
* 1: variable 'Y' is unbound
3> error(goo).
** exception error: goo
4> X.
1
5> Y = self().
<0.37.0>
6> error(cthu).
** exception error: cthu
7> {Y, self()}.
{<0.37.0>,<0.41.0>}

so that "ports and ETS tables as well as processes linked to
the evaluator process" don't "survive the exception" in
contrast to variable bindings, which visibly DO survive.

The case of Y is particularly confusing.

Would it help if restarted shells printed a message
"Shell restarted: associated ports, ETS tables, and links lost."
?




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...