0
start_link() ->
supervisor:start_link(m_supervisor, []).

init(_Args) ->
{ok, {{one_for_one, 1, 60},
      [{m_clock, {m_clock, start_link, []},
        permanent, brutal_kill, worker, [m_clock]},
        {m_sensor_f, {m_sensor_f, start_link, []},
        permanent, brutal_kill, worker, [m_sensor_f]},
        {m_sensor_c, {m_sensor_c, start_link, []},
        permanent, brutal_kill, worker, [m_sensor_c]},
        {m_converter, {m_converter, start_link, []},
        permanent, brutal_kill, worker, [m_converter]},
        {m_supervisor, {m_supervisor, start_link, []},
        permanent, brutal_kill, worker, [m_supervisor]},
        {m_display, {m_display, start_link, []},
        permanent, brutal_kill, worker, [m_display]}
        ]}}.

如何在一个主管中监督多个模块?

当我开始运行这个主管时,它告诉我:

** exception exit: {shutdown,
                   {failed_to_start_child,m_sensor_f,
                       {badarg,
                           [{erlang,register,[sensor,<0.51.0>],[]},
                            {m_sensor_f,start_sensor_f,2,
                                [{file,"m_sensor_f.erl"},{line,46}]},
                            {m_sensor_f,init,1,
                                [{file,"m_sensor_f.erl"},{line,16}]},
                            {gen_server,init_it,6,
                                [{file,"gen_server.erl"},{line,306}]},
                            {proc_lib,init_p_do_apply,3,
                                [{file,"proc_lib.erl"},{line,237}]}]}}}

我怎么解决这个问题?

4

1 回答 1

1

代码的问题是您试图再次启动同一个主管作为它自己的孩子。所以它会进入无限循环并在第二次注册同名进程时失败。

> {m_supervisor, {m_supervisor, start_link, []},
>         permanent, brutal_kill, worker, [m_supervisor]},
于 2015-03-13T17:11:04.897 回答