<div dir="ltr">ha ha, good analogy, thanks Rick!<div><br></div><div>+ Harit</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 13, 2015 at 3:17 PM, Rick Pettit <span dir="ltr"><<a href="mailto:rpettit@vailsys.com" target="_blank">rpettit@vailsys.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think you want to replace your call to exit/1 with an appropriate call to exit/2.<br>
<br>
The way you have it written your shell is committing suicide (as opposed to murder :-)<br>
<span class="HOEnZb"><font color="#888888"><br>
-Rick<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Jan 13, 2015, at 4:23 PM, Harit Himanshu <<a href="mailto:harit.subscriptions@gmail.com">harit.subscriptions@gmail.com</a>> wrote:<br>
<br>
> The problem I am trying while learning from exercises from Joe's book is<br>
><br>
> 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>
><br>
> So I created the runner and monitor_runner as<br>
><br>
> runner() -><br>
>   receive<br>
>   after 5 * 1000 -><br>
>     io:format("I am running.~n"),<br>
>     runner()<br>
>   end.<br>
><br>
> monitor_runner() -><br>
>   spawn(fun() -><br>
>     {Pid, Ref} = spawn_monitor(error_handling, runner, []),<br>
>     io:format("started new process ~p and reference ~p.~n", [Pid, Ref]),<br>
>     register(runner, Pid),<br>
>     receive<br>
>       {'DOWN', Ref, process, Pid, _Why} -><br>
>         io:format("runner got killed, restarting"),<br>
>         monitor_runner();<br>
>       X -> X<br>
>     end<br>
>   end).<br>
><br>
><br>
> When I run this, I get<br>
> 1> c(error_handling).<br>
> {ok,error_handling}<br>
> 2> Pid = error_handling:monitor_runner().<br>
> started new process <0.40.0> and reference #Ref<0.0.0.77>.<br>
> <0.39.0><br>
> I am running.<br>
> 3><br>
> 3><br>
> I am running.<br>
> 3> Pid.<br>
> <0.39.0><br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> 4> whereis(runner).<br>
> <0.40.0><br>
> I am running.<br>
> 6> exit(whereis(runner)).<br>
> ** exception exit: <0.40.0><br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> I am running.<br>
> 7><br>
><br>
> Problem?<br>
>  The runner is still running.<br>
> 1.) Why is the process not getting killed?<br>
> 2.) Why is it not caught by {'DOWN'....}<br>
><br>
> What am I missing here?<br>
><br>
> Thanks<br>
> + Harit<br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">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>
</div></div></blockquote></div><br></div>