我有一个 Erlangsupervisor
来监督基于 的工作服务器的进程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]}}.