<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi guys,<br>
<br>
In the Joe's book <<progamming erlang>>, page 163, there
are some description about exit signal :<br>
<br>
When an exit signal arrives at a process, then a number of different<br>
things might happen. What happens depends upon the state of the<br>
receiving process and upon the value of the exit signal and is
deter-<br>
mined by the following table:<br>
<img src="cid:part1.02040807.01070402@7road.com" alt=""><br>
<br>
but when use edemo1:start(true, {die, kill}), the result is:<br>
<br>
<pre>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
</pre>
Why process b is alive? Cause as the descripion in this book, when
the exit signal
<pre>{'EXIT',<0.73.0>,kill}</pre>
arrived, the process b will die and broadcast the exit signal killed
to the link set.<br>
<br>
the souce code of edemo1 module as following:<br>
<br>
<pre>%% ---
%% 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 <a class="moz-txt-link-freetext" href="http://www.pragmaticprogrammer.com/titles/jaerlang">http://www.pragmaticprogrammer.com/titles/jaerlang</a> 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.
</pre>
<br>
</body>
</html>