2014-03-04 71 views
0

我有一个Erlang supervisor,监督一个基于gen_server工作服务器的过程,我开始form the shell我的主管,这反过来启动我的工作服务器没有问题,它看起来像这样:监督员崩溃时,工作人员,其中监督员不应该

start_link() -> 
    supervisor:start_link({local, ?SERVER}, ?MODULE, []). 

但是,当我崩溃我的工作服务器,我的主管因为未知原因崩溃。

我在互联网上找到了这一个解决方法,我用这个:

start_link_shell() -> 
    {ok,Pid} = supervisor:start_link({local, ?SERVER}, ?MODULE, []), 
    unlink(Pid). 

现在工作得很好,但我不明白为什么,谁能解释一下吗?


**

更新

**

这是我的初始化函数

%%%=================================================================== 

init([]) -> 

    % Building Supervisor specifications 

    RestartStrategy = one_for_one, 
    MaxRestarts = 2, 
    MaxSecondsBetweenRestarts = 5000, 

    SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, 


    % Building Child specifications 

    Restart = permanent, 
    Shutdown = 2000, % Number of seconds the child is allowed to run after receiving shutdown message 
    Type = worker, 

    ChildSpec = {'db_server', 
       {'db_server', start_link, []}, 
       Restart, 
       Shutdown, 
       Type, 
       ['db_server']}, 


    % Putting Supervisor and Child(ren) specifications in the return 

    {ok, {SupFlags, [ChildSpec]}}. 
+0

你的超级用户回调模块中的init函数是什么样的? – legoscia

+0

@legoscia,没什么不寻常的,但看看我在问题中的更新 – securecurve

回答

0

按本link

公关来自shell的会话测试主管是监督进程与shell进程相关联。当gen_server进程崩溃时,退出信号会传播到崩溃并重新启动的shell,并且仅用于测试,否则,OTP应用程序应该启动监督器并将其链接到它。