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}]}]}}}
我该如何解决这个问题?
答案 0 :(得分:1)
代码的问题在于您尝试再次启动与其自己的子项相同的管理程序。因此,它将进入无限循环并在第二次使用相同名称注册进程时失败。
> {m_supervisor, {m_supervisor, start_link, []},
> permanent, brutal_kill, worker, [m_supervisor]},