读书人

erlang:monitor/二使用范例

发布时间: 2013-11-08 17:52:14 作者: rapoo

erlang:monitor/2使用范例

-module(test_monitor).-compile(export_all).test() ->    P = spawn(fun() -> receive ok -> ok end end),    erlang:monitor(process, P),        P ! test,    io:format("send test~n"),    timer:sleep(1000),    receive Msg -> io:format("~p~n", [Msg])    after 0 -> io:format("timeout~n")    end,        P ! ok,    io:format("send ok~n"),    timer:sleep(1000),    receive Msg1 -> io:format("~p~n", [Msg1])    after 0 -> io:format("timeout~n")    end.    %% 16> test_monitor:test().%% send test%% timeout%% send ok%% {'DOWN',#Ref<0.0.0.334>,process,<0.86.0>,normal}%% ok

?

读书人网 >开源软件

热点推荐