- 论坛徽章:
- 27
|
- -module(m_sup).
- -behaviour(supervisor).
- -export([init/1]).
- -compile(export_all).
- start_link() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
- init(_Args)->
- {ok,{{one_for_one, 1,1},
- [{m,{m,start_link,[3000]},
- permanent,brutal_kill,worker,[m]}]
- }
- }.
复制代码- -module(m).
- -compile(export_all).
- do_check(URL)->
- Method = get,
- Request = {URL, []},
- %Options = [{sync, false}],
- Options = [],
- {ok, {{Version, 200, ReasonPhrase}, _, _}} = httpc:request(Method, Request, [], Options),
- T=calendar:now_to_local_time(erlang:now()),
- io:format("Check time: ~p ~p ~p~n",[T,Version,ReasonPhrase]).
-
- start_link(Time) ->
- inets:start(),
- Pid=spawn(fun()->timer(Time) end),
- {ok,Pid}.
- cancel(Pid) -> Pid ! cancel.
- timer(Time) ->
- receive
- cancel ->
- void
- after Time ->
- do_check("http://www.baidu.com/"),
- %io:format("~p~n",["ssssssssss"]),
- timer(Time)
- end.
-
复制代码 |
|