<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello Steve,<div><br></div><div>Thanks for your response. I want to check if the supervisor is doing its job. Whats the best way for me to simulate an abnormal termination.</div><div><br></div><div>Cheers</div><div>Kamrul<br><div><hr id="stopSpelling">Date: Fri, 20 Nov 2015 18:53:11 +0000<br>From: steve@srstrong.com<br>To: ulf@feuerlabs.com; dodul@live.com<br>CC: erlang-questions@erlang.org<br>Subject: Re: [erlang-questions] Supervising UDP listener<br><br>

<title></title>


<div>You create udp_listener with spawn_link, which would kill the parent *if* udp_listener terminates abnormally. In your case, udp_listener is exiting cleanly, so it won't cause the parent to die.</div>
<div><img src="https://img.smartmailcloud.com/dot/XREADDLEPUSHTOKENXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.gif" width="0" height="0" style="display:block;"></div><div><br>
Cheers.<br>
<br>
Steve<br>
<br>
--<br>
Steve Strong<br>
Sent with Airmail</div>
<div><br>
On 20 Nov 2015, 17:38 +0000, Kamrul Khan <dodul@live.com>, wrote:<br>
<blockquote>
<div dir="ltr">I didnt get any response for my question. I am posting it again ( with the typo fix)
<div><br></div>
<div><span style="color:rgb(68, 68, 68);font-size:15px;line-height:21.3px;background-color:rgb(255, 255, 255);">I am trying to make a UDP listener that will be supervised by a supervisor module (Just for learning purpose).  below id my Supervisor code:</span>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);">
<div style="line-height:21.3px;">-module(pdmanager_sup).</div>
<div style="line-height:21.3px;">-behaviour(supervisor).</div>
<div style="line-height:21.3px;"> </div>
<div style="line-height:21.3px;">-export([start_link/1]).</div>
<div style="line-height:21.3px;">-export([init/1]).</div>
<div style="line-height:21.3px;"> </div>
<div style="line-height:21.3px;">start_link(Port) -></div>
<div style="line-height:21.3px;">supervisor:start_link({local,?MODULE}, ?MODULE, Port).</div>
<div style="line-height:21.3px;"> </div>
<div style="line-height:21.3px;">init(Port) -></div>
<div style="line-height:21.3px;">    {ok, {{one_for_one, 5, 60},</div>
<div style="line-height:21.3px;">        [{listener,</div>
<div style="line-height:21.3px;">            {pdmanager, start_link, Port},</div>
<div style="line-height:21.3px;">            permanent, 1000, worker, [pdmanager]}</div>
<div style="line-height:21.3px;">        ]}}.</div>
<div style="line-height:21.3px;"><br style="line-height:21.3px;"></div>
</div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);">And my udp listener (pdmanager) looks like the below:</div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);">
<div style="line-height:21.3px;">-module(pdmanager).</div>
<div style="line-height:21.3px;">-behaviour(gen_server).</div>
<div style="line-height:21.3px;"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;">-export([start_link/1]).</div>
<div style="line-height:21.3px;">-export([init/1]).</div>
<div style="line-height:21.3px;">-export([</div>
<div style="line-height:21.3px;">    udplistener/1,</div>
<div style="line-height:21.3px;">    handleudp/1</div>
<div style="line-height:21.3px;">]).</div>
<div style="line-height:21.3px;"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;">-record(state, {socket}).</div>
<div style="line-height:21.3px;"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;">start_link(Port) -></div>
<div style="line-height:21.3px;">    gen_server:start_link({local, pdmanager}, pdmanager, Port, []).</div>
<div style="line-height:21.3px;"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;">init(Port) -></div>
<div style="line-height:21.3px;">    io:format("UDP Server starting ~n",[]),</div>
<div style="line-height:21.3px;">    {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]),</div>
<div style="line-height:21.3px;">    spawn_link(pdmanager,udplistener,[Socket]),</div>
<div style="line-height:21.3px;">    {ok, #state{socket=Socket}}.</div>
<div style="line-height:21.3px;"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;">udplistener(Socket) -></div>
<div style="line-height:21.3px;">    {ok,Packet} = gen_udp:recv(Socket,0),</div>
<div style="line-height:21.3px;">    {_,_,Msg} = Packet,</div>
<div style="line-height:21.3px;">    if</div>
<div style="line-height:21.3px;">        Msg /= "stop" -></div>
<div style="line-height:21.3px;">            io:format("Stoping UDP listener ~n", []);</div>
<div style="line-height:21.3px;">        true -></div>
<div style="line-height:21.3px;">            spawn(pdmanager,handleudp,[Packet]),</div>
<div style="line-height:21.3px;">            udplistener(Socket)</div>
<div style="line-height:21.3px;">    end.</div>
<div style="line-height:21.3px;">    </div>
<div style="line-height:21.3px;">handleudp(Packet) -></div>
<div style="line-height:21.3px;">    {_,_, Msg} = Packet,</div>
<div style="line-height:21.3px;">    io:format("I have got message : ~s ~n",[Msg]),</div>
<div style="line-height:21.3px;">    {handeling, Packet}.</div>
</div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);">Now: after compiling I start my program with :</div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);">pdmanager_sup:start_link(5678).</div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><br style="line-height:21.3px;"></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);">It gets started and I can see the "UDP server starting" message in my screen. Next, when I send a message to UDP 5678 port I see the message "s<span style="line-height:22.72px;font-size:12pt;">toping UDP listener</span><span style="line-height:22.72px;font-size:12pt;">" as expected.  However, it doesnt restart my server.  I called udplistener/1 function from init/1 using spawn_link. I expected spawn_link will link the new process (udp listener) with the calling process (the worker process in this case) and if udplistener goes down the worker will go down aswell and that will cause the supervisor to restart the worker. However, I didnt work that way. </span></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><span style="line-height:22.72px;font-size:12pt;"><br style="line-height:22.72px;"></span></div>
<div style="line-height:21.3px;color:rgb(68, 68, 68);font-size:15px;background-color:rgb(255, 255, 255);"><span style="line-height:22.72px;font-size:12pt;">How should I do it ? </span></div>
<br>
<div>
<hr id="ecxstopSpelling">
From: dodul@live.com<br>
To: ulf@feuerlabs.com<br>
Date: Fri, 20 Nov 2015 13:33:13 +0600<br>
CC: erlang-questions@erlang.org<br>
Subject: Re: [erlang-questions] Supervising UDP listener<br>
<br>
<style><!--
.ExternalClass body.ecxhmmessage {
font-size:12pt;
font-family:Calibri;
}
--></style>
<div dir="ltr">Typo. Sorry about that. should be 
<div>pdmanager_sup:start_link(5678).<br>
<br>
<div>
<hr id="ecxstopSpelling">
Subject: Re: [erlang-questions] Supervising UDP listener<br>
From: ulf@feuerlabs.com<br>
Date: Thu, 19 Nov 2015 21:56:09 -0800<br>
CC: erlang-questions@erlang.org<br>
To: dodul@live.com<br>
<br>
<br>
<div>
<blockquote>
<div>On 19 Nov 2015, at 15:45, Kamrul Khan <<a href="mailto:dodul@live.com">dodul@live.com</a>> wrote:</div>
<br class="ecxApple-interchange-newline">
<div>
<div style="font-family:Calibri;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">Now: after compiling I start my program with :</div>
<div style="font-family:Calibri;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><br></div>
<div style="font-family:Calibri;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">pdmanager:start_link(5678).</div>
<br class="ecxApple-interchange-newline"></div>
</blockquote>
</div>
<br>
<div>Not pdmanager_sup:start_link(5678)?</div>
<div><br></div>
<div>BR,</div>
<div>Ulf W</div>
</div>
</div>
</div>
<br>
_______________________________________________ erlang-questions mailing list erlang-questions@erlang.org http://erlang.org/mailman/listinfo/erlang-questions</div>
</div>
</div>
_______________________________________________<br>
erlang-questions mailing list<br>
erlang-questions@erlang.org<br>
http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote>
</div></div></div>                                      </div></body>
</html>