restarting child processes

Chris Campbell cyberdanx@REDACTED
Wed Oct 19 23:00:12 CEST 2005


Hi,

I'm playing with the supervisor behaviour but for some reason it
always terminates after a problem with the child.  The program is a
little contrieved to learn about the behaviour.  The child is to
terminate if it doesn't receive a message within 750ms.  The
supervisor should restart it indefinitely, instead it terminates.


Here is the child module.

% swf_kid.erl
-module(swf_kid).
-export([start_child/0, child_work/0, stop_child/1]).


start_child() ->
    child_work().

child_work() ->
    receive
        stop ->
            io:format("stopping!~n"),
            ok;
        Others ->
            child_work()
    after 750 ->
            io:format("child exiting~n"),
            exit(blah)
    end.

stop_child(C) ->
    C ! stop.

and here is the supervisor.

% swf_supervisor.erl
-module(swf_supervisor).
-behaviour(supervisor).
-export([start_link/0, init/1]).


start_link() ->
    supervisor:start_link(swf_supervisor, []).

init(_X) ->
    {ok, {{one_for_one, 50, 1},
          [{kid, {swf_kid, start_child, []},
            permanent, brutal_kill, worker, []}]}}.

This gives the following error (with sasl)...

> swf_supervisor:start_link().
child exiting

=SUPERVISOR REPORT==== 19-Oct-2005::21:52:53 ===
     Supervisor: {<0.256.0>,swf_supervisor}
     Context:    start_error
     Reason:     {'EXIT',blah}
     Offender:   [{pid,undefined},
                  {name,kid},
                  {mfa,{swf_kid,start_child,[]}},
                  {restart_type,permanent},
                  {shutdown,brutal_kill},
                  {child_type,worker}]

** exited: shutdown **

Why isn't the child being restarted?


Regards,
Chris



More information about the erlang-questions mailing list