浏览 338 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-03-06
各位好!最近在学习otp,参考www.trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles写一个程序。
我在父进程用supervisor启动2个子进程,tcp_accept,tcp_client_sup,发现tcp_accept可以启动会有运行信息被打印出来,但是tcp_client_sup在执行时会shutdown。 启动进程代码如下: server_sup
-module(server_sup).
-behaviour(supervisor).
-include ("./include/setting.hrl").
-export([start_link/1,test_start/0,init/1]).
%%Server supervisor
start_link(Args) ->
?DEBUG("server_sup start_link\r\n",[]),
supervisor:start_link({local,?MODULE}, ?MODULE, Args).
test_start()->
{ok, Pid} = supervisor:start_link({local,?MODULE}, ?MODULE, _Arg = []).
%%unlink(Pid).
init([]) ->
?DEBUG("server_sup init\r\n",[]),
{ok, {{one_for_one, ?MAX_RESTART, ?MAX_TIME},
[
{tcp_accept,
{tcp_accept, start_link, []},
permanent,
?SHUTDOWN_WAITING_TIME,
worker,
[]},
{
tcp_client_sup,
{tcp_client_sup, start_link, [tcp_client_recv]},
permanent,
infinity,
supervisor,
[]
}
]}}.
tcp_client_sup代码:
-module(tcp_client_sup).
-behaviour(supervisor).
-include ("./include/setting.hrl").
-export([start_link/1,init/1,start_child/1]).
%%Client connection supervisor
start_link(Module) ->
?DEBUG("tcp_client_sup start_link ~s\r\n",[?MODULE]),
supervisor:start_link({local,?MODULE}, ?MODULE, Module).
start_child([]) ->
?DEBUG("tcp_client_sup start_child\r\n",[]),
supervisor:start_child(?MODULE, []).
init(Module) ->
?DEBUG("tcp_client_sup init\r\n",[]),
{ok, {{simple_one_for_one, ?MAX_RESTART, ?MAX_TIME}, [{
undefined,
{tcp_client_recv, start_link, []},
temporary,
?SHUTDOWN_WAITING_TIME,
worker,
[]
}]}}.
执行server_sup:test_start(). 输出: 58> server_sup:test_start(). server_sup init tcp_accept start_link tcp_accept init tcp_accept accept tcp_client_sup start_child ** exception exit: shutdown 修改了下程序,一些小问题造成的,现在又向前进了一步,在start_child的部分shutdown。 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2008-03-06
封贴了,被一些零碎问题搞混乱了,已经解决了。
|
|
| 返回顶楼 | |


