Erlang leader and leader

I have a question about a supervisor. For example, I have 1 dispatcher, and I need to start start_child for this supervisor. Should I start, first of all, start my leader? Or can I only supervisor:start_child(my_sup,[])without running my_sup?

Thank.

+3
source share
2 answers

First, you create a supervisor process as part of an observation tree that calls supervisor:start_link/2or supervisor:start_link/3. The created dispatcher process calls Module:init/1to inquire about the restart strategy, maximum restart frequency and detailed specifications.

This is sample code for a supervisor starting gen_server (although you can run other gen_ * modules):

-module(ch_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
start_link() ->
    supervisor:start_link(ch_sup, []).
init(_Args) ->
    {ok, {{one_for_one, 1, 60},
          [{ch3, {ch3, start_link, []},
            permanent, brutal_kill, worker, [ch3]}]}}.

{ch3, ...} , :

{Id, StartFunc, Restart, Shutdown, Type, Modules}

ch3 :

{ch3, {ch3, start_link, []}, permanent, brutal_kill, worker, [ch3]}

, ch3 , , one_for_one , . one_for_one , , , , , . , , .

start_child/2 SupRef, .

, supervisour , .

+3

, , , - , . , .

0

Source: https://habr.com/ru/post/1788568/


All Articles