[erlang-bugs] Fwd: exit(self(), normal) causes calling process to exit
Robert Virding
robert.virding@REDACTED
Sun Dec 2 11:02:16 CET 2012
No. '!' is *only* used for sending messages.
Exit signals, generated when a process dies or by calling exit/2, are not messages and can not be sent using '!'. When trapping exits and an exit signal arrives at the process it is *CONVERTED* to a message of the form {'EXIT',Pid,Reason} and put in the process's message queue. You will not get the effect of a signal by sending a message with the same format to a process. For example a message will not crash a process.
In the basic language there are no special messages which do things to processes beyond that which is explicitly done in code. Even the messages sent by OTP are special only because OTP chooses to interpret them in a special way.
So messages and signals are two different things, sent in two different ways and have different meanings.
Robert
----- Original Message -----
> From: "Bengt Kleberg" <bengt.kleberg@REDACTED>
> To: "Robert Virding" <robert.virding@REDACTED>
> Cc: erlang-bugs@REDACTED, "Patrik Nyblom" <pan@REDACTED>
> Sent: Sunday, 2 December, 2012 9:13:57 AM
> Subject: SV: [erlang-bugs] Fwd: exit(self(), normal) causes calling process to exit
>
> Greetings,
>
> Is not '!' used for sending signals (and other stuff)?
>
> Bengt
>
> Sent from Moxier Mail
> (http://www.moxier.com)
>
>
> ----- Ursprungligt meddelande -----
> Från: Robert Virding <robert.virding@REDACTED>
> Till: Patrik Nyblom <pan@REDACTED>
> Kopia: "erlang-bugs@REDACTED" <erlang-bugs@REDACTED>
> Skickat: 02-12-2012 3:14 fm
> Ämne: Re: [erlang-bugs] Fwd: exit(self(), normal) causes calling
> process to exit
>
>
>
> Just to say that I concur that this is definitely a bug, exit/2
> always sends a signal, even if the process is sending to itself, and
> that signal is to be treated in the same way irrespective of who
> sent it. Unfortunately the bug has been there a long time.
>
> In retrospect it would might have been better to call it signal/2
> instead.
>
> Robert
>
> ----- Original Message -----
> > From: "Patrik Nyblom" <pan@REDACTED>
> > To: erlang-bugs@REDACTED
> > Sent: Thursday, 29 November, 2012 7:10:02 PM
> > Subject: Re: [erlang-bugs] Fwd: exit(self(), normal) causes calling
> > process to exit
> >
> > On 11/28/2012 08:50 PM, Daniel Luna wrote:
> > > I withdraw my comment. It's still true that it works when
> > > trapping
> > > exits, but apparently you shouldn't have to.
> > >
> > > From the docs:
> > >
> > > "If Reason is the atom normal, Pid will not exit."
> > >
> > > I call bug on this.
> > I agree. It's in the pipe.
> > >
> > > Cheers,
> > >
> > > Daniel
> >
> > Cheers,
> > /Patrik
> > >
> > > On 28 November 2012 13:07, Daniel Luna <daniel@REDACTED> wrote:
> > >> I replied on StackOverflow, but the gist of the problem is that
> > >> you
> > >> don't trap exits.
> > >>
> > >> 1> self().
> > >> <0.32.0>
> > >> 2> process_flag(trap_exit, true).
> > >> false
> > >> 3> exit(self(), normal).
> > >> true
> > >> 4> self().
> > >> <0.32.0>
> > >> 5> flush().
> > >> Shell got {'EXIT',<0.32.0>,normal}
> > >> ok
> > >>
> > >> Cheers,
> > >>
> > >> Daniel
> > >>
> > >> On 28 November 2012 11:50, Stavros Aronis <aronisstav@REDACTED>
> > >> wrote:
> > >>> After some speculation on stackoverflow I think I will report
> > >>> this here as
> > >>> well. (I am directly copying the content of the question.)
> > >>>
> > >>> I am playing around with the exit/2 function and its behavior
> > >>> when self() is
> > >>> used as a Pid and normal as a Reason.
> > >>>
> > >>> Erlang R15B03 (erts-5.9.3) [source] [64-bit] [smp:8:8]
> > >>> [async-threads:0]
> > >>> [hipe] [kernel-poll:false]
> > >>>
> > >>> Eshell V5.9.3 (abort with ^G)
> > >>> 1> self().
> > >>> <0.32.0>
> > >>> 2> exit(self(), normal).
> > >>> ** exception exit: normal
> > >>> 3> self().
> > >>> <0.35.0>
> > >>>
> > >>> Shouldn't it be the case that only a 'normal' exit message is
> > >>> sent to the
> > >>> shell process, so there is no reason to exit?
> > >>>
> > >>> Similarly:
> > >>>
> > >>> 4> spawn(fun() -> receive Pid -> Pid ! ok end end).
> > >>> <0.38.0>
> > >>> 5> exit(v(4), normal).
> > >>> true
> > >>> 6> v(4) ! self().
> > >>> <0.35.0>
> > >>> 7> flush().
> > >>> Shell got ok
> > >>> ok
> > >>>
> > >>> But:
> > >>>
> > >>> 8> spawn(fun() -> exit(self(), normal), receive _ -> ok end
> > >>> end).
> > >>> <0.43.0>
> > >>> 9> is_process_alive(v(8)).
> > >>> false
> > >>>
> > >>>
> > >>> _______________________________________________
> > >>> erlang-bugs mailing list
> > >>> erlang-bugs@REDACTED
> > >>> http://erlang.org/mailman/listinfo/erlang-bugs
> > >>>
> > > _______________________________________________
> > > erlang-bugs mailing list
> > > erlang-bugs@REDACTED
> > > http://erlang.org/mailman/listinfo/erlang-bugs
> >
> > _______________________________________________
> > erlang-bugs mailing list
> > erlang-bugs@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-bugs
> >
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
>
More information about the erlang-bugs
mailing list