[erlang-questions] Some problem abount exit signal?

Ulf Wiger <>
Thu Dec 2 08:00:24 CET 2010


Process C terminates itself with exit(kill). The atom 'kill'
is not special in this case, but simply a normal exit reason.

A propagated exit signal can never act as a kill signal in the 
first place, but here, not even the original exit is an untrappable
kill.

Try:

Eshell V5.8.1  (abort with ^G)
1> self().
<0.31.0>
2> catch exit(kill).
{'EXIT',kill}
3> self().
<0.31.0>

BR,
Ulf W

On 2 Dec 2010, at 05:37, sky wrote:

> Hi guys,
> 
> In the Joe's book <<progamming erlang>>, page 163, there are some description about exit signal :
> 
> When an exit signal arrives at a process, then a number of different
> things might happen. What happens depends upon the state of the
> receiving process and upon the value of the exit signal and is deter-
> mined by the following table:
> <moz-screenshot.png>
> 
> but when use edemo1:start(true, {die, kill}), the result is:
> 
> edemo1:start(true, {die,kill}).
> Process b received {'EXIT',<0.73.0>,kill}
> process b (<0.72.0>) is alive
> process c (<0.73.0>) is dead
> ok
> Why process b is alive? Cause as the descripion in this book,  when the exit signal
> {'EXIT',<0.73.0>,kill}
> arrived, the process b will die and broadcast the exit signal killed to the link set.
> 
> the souce code of edemo1 module as following:
> 
> %% ---
> %%  Excerpted from "Programming Erlang",
> %%  published by The Pragmatic Bookshelf.
> %%  Copyrights apply to this code. It may not be used to create training material, 
> %%  courses, books, articles, and the like. Contact us if you are in doubt.
> %%  We make no guarantees that this code is fit for any purpose. 
> %%  Visit http://www.pragmaticprogrammer.com/titles/jaerlang for more book information.
> %%---
> 
> -module(edemo1).
> -export([start/2]).
> 
> start(Bool, M) ->
>     A = spawn(fun() -> a() end),
>     B = spawn(fun() -> b(A, Bool) end),
>     C = spawn(fun() -> c(B, M) end),
>     sleep(1000),
>     status(b, B),
>     status(c, C).
> 
> 
> a() ->      
>     process_flag(trap_exit, true),
>     wait(a).
> 
> b(A, Bool) ->
>     process_flag(trap_exit, Bool),
>     link(A),
>     wait(b).
> 
> c(B, M) ->
>     link(B),
>     case M of
> 	{die, Reason} ->
> 	    exit(Reason);
> 	{divide, N} ->
> 	    1/N,
> 	    wait(c);
> 	normal ->
> 	    true
>     end.
> 
> 
> 
> wait(Prog) ->
>     receive
> 	Any ->
> 	    io:format("Process ~p received ~p~n",[Prog, Any]),
> 	    wait(Prog)
>     end.
> 
> 
> 
> sleep(T) ->
>     receive
>     after T -> true
>     end.
> 
> status(Name, Pid) ->	    
>     case erlang:is_process_alive(Pid) of
> 	true ->
> 	    io:format("process ~p (~p) is alive~n", [Name, Pid]);
> 	false ->
> 	    io:format("process ~p (~p) is dead~n", [Name,Pid])
>     end.
> 
> 

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com





More information about the erlang-questions mailing list