<div dir="ltr">you are right Felix, exit/1 did not help.<div><br></div><div>Instead I tried timer:kill_after() and this seems to work as expected. I made no changes to code, only changed how to kill the registered process and it started to work</div><div><br></div><div><br></div><div><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">1> c(error_handling).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">{ok,error_handling}</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">2> error_handling:monitor_runner().</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">started new process <0.40.0> and reference #Ref<0.0.0.77>.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)"><0.39.0></p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.             </p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.                            </p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">3> timer:kill_after(3000, whereis(runner)).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">{ok,{1421188290386972,#Ref<0.0.0.88>}}</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">runner got killed, restarting.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">started new process <0.45.0> and reference #Ref<0.0.0.95>.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.                              </p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">4> timer:kill_after(3000, whereis(runner)).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">{ok,{1421188310002128,#Ref<0.0.0.101>}}</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">runner got killed, restarting.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">started new process <0.48.0> and reference #Ref<0.0.0.107>.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">5> </p></div><div><br></div><div>Thank you</div><div>+ Harit Himanshu</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 13, 2015 at 2:31 PM, Felix Gallo <span dir="ltr"><<a href="mailto:felixgallo@gmail.com" target="_blank">felixgallo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">exit/1 doesn't do what you think it does.  Maybe try exit/2?</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Jan 13, 2015 at 2:23 PM, Harit Himanshu <span dir="ltr"><<a href="mailto:harit.subscriptions@gmail.com" target="_blank">harit.subscriptions@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">The problem I am trying while learning from exercises from Joe's book is <div><br></div><div>Write a function that creates a registered process that writes out "I’m still running" every five seconds. Write a function that monitors this process and restarts it if it dies. Start the global process and the monitor process. Kill the global process and check that it has been restarted by the monitor process.<br></div><div><br></div><div>So I created the runner and monitor_runner as  </div><div><br></div><div><div>runner() -></div><div>  receive</div><div>  after 5 * 1000 -></div><div>    io:format("I am running.~n"),</div><div>    runner()</div><div>  end.</div><div><br></div><div>monitor_runner() -></div><div>  spawn(fun() -></div><div>    {Pid, Ref} = spawn_monitor(error_handling, runner, []),</div><div>    io:format("started new process ~p and reference ~p.~n", [Pid, Ref]),</div><div>    register(runner, Pid),</div><div>    receive</div><div>      {'DOWN', Ref, process, Pid, _Why} -></div><div>        io:format("runner got killed, restarting"),</div><div>        monitor_runner();</div><div>      X -> X</div><div>    end</div><div>  end).</div></div><div><br></div><div><br></div><div>When I run this, I get  </div><div><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">1> c(error_handling).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">{ok,error_handling}</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">2> Pid = error_handling:monitor_runner().</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">started new process <0.40.0> and reference #Ref<0.0.0.77>.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)"><0.39.0></p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">3> </p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">3> </p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">3> Pid.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)"><0.39.0></p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">4> whereis(runner).</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)"><0.40.0></p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">

</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">6> exit(whereis(runner)).</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">** exception exit: <0.40.0></p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">I am running.</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">








</p><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">7> </p></div><div><br></div><div><b>Problem?</b></div><div> The runner is still running.</div><div>1.) Why is the process not getting killed?</div><div>2.) Why is it not caught by {'DOWN'....}</div><div><br></div><div>What am I missing here?</div><div><br></div><div>Thanks</div><span><font color="#888888"><div>+ Harit</div></font></span></div>
<br></div></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>