I run the example link_demo(page 103) in Erlang book:<br><br><br>-module(link_demo).<br><br>%%<br>%% Include files<br>%%<br><br>%%<br>%% Exported Functions<br>%%<br>-export([start/0,demo/0,demonstrate_normal/0,<br> demonstrate_exit/1, demonstrate_error/0,demonstrate_message/1]).
<br><br>%%<br>%% API Functions<br>%%<br><br>start() -><br> register(demo, spawn(link_demo, demo, [])).<br><br>demo() -><br> process_flag(trap_exit, true),<br> demo1().<br><br>demo1() -><br> receive <br>
{'EXIT', From, normal} -><br> io:format("Demo process received normal exit from ~w~n", [From]),<br> demo1();<br> {'EXIT', From, Reason} -><br> io:format("Demo process received exit signal ~w from ~w~n", [Reason, From]),
<br> demo1();<br> finished_demo -><br> io:format("Demo finished ~n", []);<br> Other -><br> io:format("Demo process message ~w~n", [Other]),<br> demo1()
<br> end.<br><br><br>%%<br>%% Local Functions<br>%%<br><br>demonstrate_normal() -><br> link(whereis(demo)).<br><br>demonstrate_exit(What) -><br> link(whereis(demo)),<br> exit(What).<br>demonstrate_message(What) ->
<br> demo ! What.<br>demonstrate_error()-><br> link(whereis(demo)),<br> 1 = 2.<br><br>-----------<br>After start(), I call demonstrate_normal(), demo process should trap the exit(normal) signal, but it doesn't,
<br> and if I call demonstrate_exit(normal) , demo do trap the exit(normal).<br><br>The only difference between theses two situations is the exiting process call exit/1 explicitly. <br><br>Must I call exit before existing ?
<br><br>My environment: MacBook(Intel) <br>Erlang (BEAM) emulator version 5.5 [source] [async-threads:0]<br><br>Eshell V5.5 (abort with ^G)<br>1> <br><br>Thanks!<br>Best Regards<br>James<br>