[erlang-questions] spawn_link/2 behaviour
Chandru
chandrashekhar.mullaparthi@REDACTED
Tue Nov 24 00:04:05 CET 2015
Hi Avinash,
See http://www.erlang.org/doc/getting_started/robustness.html#id69577
<quote>
The default behaviour of a process that receives a normal exit is to ignore
the signal.
</quote>
If you change the local_loop function as shown below, you will get the
behaviour you are expecting.
local_loop() ->
receive
stop ->
io:format("stopped~n"),
exit(stopped);
X ->
io:format("~p~n", [X]),
local_loop()
end.
cheers,
Chandru
On 21 November 2015 at 11:49, Avinash Dhumane <nistrigunya@REDACTED> wrote:
> Hello,
>
> I have following test program (on Windows):
>
> D:\Balin\Algo_v6\v0.5>type my_test.erl
> -module(my_test).
> -export([start/0]).
>
> start() ->
> register(?MODULE,
> spawn(fun() ->
> init(),
> local_loop()
> end)).
>
> init() ->
> spawn_link('feed@REDACTED',
> fun() ->
> register(?MODULE, self()),
> remote_loop()
> end),
>
> spawn('feed@REDACTED',
> fun() ->
> timer:sleep(timer:seconds(5)), % wait till the above process is
> registered
> ?MODULE ! hello,
> ?MODULE ! world,
> ?MODULE ! stop
> end).
>
> remote_loop() ->
> receive
> X ->
> {?MODULE, 'algo@REDACTED'} ! X,
> remote_loop()
> end.
>
> local_loop() ->
> receive
> stop ->
> io:format("stopped~n");
> X ->
> io:format("~p~n", [X]),
> local_loop()
> end.
>
> D:\Balin\Algo_v6\v0.5>
>
> Then, I start 2 nodes, as follows:
>
> D:\Balin\Algo_v6\v0.5>start erl -name algo@REDACTED
>
> D:\Balin\Algo_v6\v0.5>start erl -name feed@REDACTED
>
> On the 'algo@REDACTED' node, I run the program as follows:
>
> Eshell V7.0 (abort with ^G)
> (algo@REDACTED)1> rpc:call('feed@REDACTED', erlang, whereis,
> [my_test]).
> undefined
> (algo@REDACTED)2> my_test:start().
> true
> (algo@REDACTED)3> hello
> (algo@REDACTED)3> world
> (algo@REDACTED)3> stopped
> (algo@REDACTED)3> rpc:call('feed@REDACTED', erlang, whereis,
> [my_test]).
> <6755.43.0>
> (algo@REDACTED)4>
>
> The messaging works as I expected. However, the process registered as
> 'my_test' on the node 'feed@REDACTED' does not terminate. I expected it
> to terminate since I started it using spawn_link/2 from the calling process
> on 'algo@REDACTED' which terminates after receiving the 'stop' message.
>
> It keeps running, as is observed on the node 'feed@REDACTED':
>
> Eshell V7.0 (abort with ^G)
> (feed@REDACTED)1> whereis(my_test).
> <0.43.0>
> (feed@REDACTED)2>
>
> What is wrong with the setup done in the test program above that the
> linked process on another node does not terminate?
>
> Please advise.
>
> Thank you.
>
> Avinash
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151123/5ea87d12/attachment.htm>
More information about the erlang-questions
mailing list