restarting child processes

Chris Campbell cyberdanx@REDACTED
Wed Oct 19 23:59:11 CEST 2005


On 19/10/05, Lennart Ohman <lennart.ohman@REDACTED> wrote:
> Hi Chris,
> the childprocess (or worker) crashes in its init-phase. You
> can se this by examining the Context field in the supervisor
> report (start_error). The supervisor will then consider itself
> to be a failure and crash in its own initphase.

Ok.  Thanks.

> As a note, your child is actually not a proper OTP process either,
> or to put it in a more polite way :-) one can say that you have
> choose to role-your-own by not using for instance the gen_server
> behaviour.

[snip]

Ok, I rewrote it so it uses gen_server however it never times out.

% swf_kid.erl
-module(swf_kid).
-behaviour(gen_server).

-export([start_link/0, terminate/2]).
-export([init/1, handle_cast/2, handle_info/2, handle_call/3]).

start_link() ->
    io:format("Child starting~n"),
    gen_server:start_link(swf_kid, [{timeout, 750}], []).

init(_A) ->
    process_flag(trap_exit, true),
    {ok, []}.

handle_cast(_A, S) ->
    {noreply, S}.

handle_call(_R, _F, S) ->
    {reply, dont_care, S}.

handle_info(timeout, S) ->
    io:format("Child exiting!~n"),
    {stop, arghh, S}.

terminate(shutdown, _S) ->
    ok.

% 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_link, []},
            permanent, brutal_kill, worker, [swf_kid]}]}}.



More information about the erlang-questions mailing list