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
?