2014-03-04 70 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應用程序應該啓動監督器並將其鏈接到它。