[erlang-questions] Re: [erlang-bugs] Re: Re: [erlang-questions] Erlang's process not killed by exit signalreasoned by "kill"

Tony Rogvall <>
Thu Oct 29 14:15:44 CET 2009


Just to clarify some details about exit signals and trap_exit problems.

You can fake exit signals if the process is trapping exits (Also the  
name of a web site ;-)

In the code below this is illustrated by starting a process that trap  
exits. Then either do
a exit(P, foo) in test1 or P ! {'EXIT',self(),foo} in test2. Also note  
that setting the process_flag(trap_exit,true)
must be synchronized!!! (yes I stumbled right into it ;-)
Trap exits should be avoided when not 100% designed into the solution.

/Tony

-module(trap).

-compile(export_all).

start() ->
     Main = self(),
     P = spawn(fun() ->
		      process_flag(trap_exit, true),
		      Main ! ok,
		      receive {'EXIT',From,Reason} ->
			      io:format("Exit: ~p ~p\n",[From,Reason])
		      end
	      end),
     receive
	ok -> P
     end.

test1() ->
     P = start(),
     exit(P, foo).

test2() ->
     P = start(),
     P ! {'EXIT',self(),foo}.



On 29 okt 2009, at 10.57, Ulf Wiger wrote:

> Joe Armstrong wrote:
>>
>> The distinction between messages and signals is subtle.
>
> One way to verify that it is indeed as Joe says:
>
> Eshell V5.6.5  (abort with ^G)
> 1> P = spawn(fun() -> timer:sleep(infinity) end).
> <0.32.0>
> 2> P ! {'EXIT',self(),foo}.
> {'EXIT',<0.30.0>,foo}
> 3> is_process_alive(P).
> true
> 4> exit(P,foo).
> true
> 5> is_process_alive(P).
> false
> 6>
>
> In other words, you cannot fake an exit signal by sending
> an {'EXIT',P,R} message.
>
> BR,
> Ulf W
> -- 
> Ulf Wiger
> CTO, Erlang Training & Consulting Ltd
> http://www.erlang-consulting.com
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>



More information about the erlang-questions mailing list