[erlang-questions] Can not kill the registered process

Harit Himanshu harit.subscriptions@REDACTED
Wed Jan 14 00:24:09 CET 2015


ha ha, good analogy, thanks Rick!

+ Harit

On Tue, Jan 13, 2015 at 3:17 PM, Rick Pettit <rpettit@REDACTED> wrote:

> I think you want to replace your call to exit/1 with an appropriate call
> to exit/2.
>
> The way you have it written your shell is committing suicide (as opposed
> to murder :-)
>
> -Rick
>
> On Jan 13, 2015, at 4:23 PM, Harit Himanshu <harit.subscriptions@REDACTED>
> wrote:
>
> > The problem I am trying while learning from exercises from Joe's book is
> >
> > 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.
> >
> > So I created the runner and monitor_runner as
> >
> > runner() ->
> >   receive
> >   after 5 * 1000 ->
> >     io:format("I am running.~n"),
> >     runner()
> >   end.
> >
> > monitor_runner() ->
> >   spawn(fun() ->
> >     {Pid, Ref} = spawn_monitor(error_handling, runner, []),
> >     io:format("started new process ~p and reference ~p.~n", [Pid, Ref]),
> >     register(runner, Pid),
> >     receive
> >       {'DOWN', Ref, process, Pid, _Why} ->
> >         io:format("runner got killed, restarting"),
> >         monitor_runner();
> >       X -> X
> >     end
> >   end).
> >
> >
> > When I run this, I get
> > 1> c(error_handling).
> > {ok,error_handling}
> > 2> Pid = error_handling:monitor_runner().
> > started new process <0.40.0> and reference #Ref<0.0.0.77>.
> > <0.39.0>
> > I am running.
> > 3>
> > 3>
> > I am running.
> > 3> Pid.
> > <0.39.0>
> > I am running.
> > I am running.
> > I am running.
> > I am running.
> > I am running.
> > 4> whereis(runner).
> > <0.40.0>
> > I am running.
> > 6> exit(whereis(runner)).
> > ** exception exit: <0.40.0>
> > I am running.
> > I am running.
> > I am running.
> > I am running.
> > I am running.
> > I am running.
> > I am running.
> > 7>
> >
> > Problem?
> >  The runner is still running.
> > 1.) Why is the process not getting killed?
> > 2.) Why is it not caught by {'DOWN'....}
> >
> > What am I missing here?
> >
> > Thanks
> > + Harit
> > _______________________________________________
> > 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/20150113/c0eb0772/attachment.htm>


More information about the erlang-questions mailing list