欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

测试 erlang:monitor

程序员文章站 2022-07-15 23:09:22
...

测试代码

 

  1 -module(testmonitor).

  2 -compile(export_all).

 13 hello3()->

 14     receive

 15           {Pid, T} ->

 16              io:format("receive....~p~n", [T]),

 17              S = integer_to_list(T),        

 18              io:format("receive.. Pid=~p..s=~p~n", [Pid, S]),

 19              Pid ! {integer_to_list, S},

 20              hello3()

 21     end.    

 

 

测试结果:

---------------没有使用-- erlang:monitor 当出现转换错误时收到的是timeout----------

 

39> 

39>  f(),Pid = spawn(testmonitor, hello3,[]).                        

<0.85.0>

40> f(F),F = fun() ->f(A), receive A->A after 3000-> timeout end end.

#Fun<erl_eval.20.21881191>

41>  Pid ! {self(),a2}, F().                                         

receive....a2

 

=ERROR REPORT==== 28-Nov-2012::18:55:09 ===

Error in process <0.85.0> with exit value: {badarg,[{erlang,integer_to_list,[a2]},{testmonitor,hello3,0}]}

 

timeout

42> 

42> 

42> 

-使用-- erlang:monitor 当出现转换错误时收到的是{'DOWN', MonitorRef, Type, Object, Info}----

42> 

42>  f(),Pid = spawn(testmonitor, hello3,[]).                        

<0.89.0>

43> f(F),F = fun() ->f(A), receive A->A after 3000-> timeout end end.

#Fun<erl_eval.20.21881191>

44>  R=erlang:monitor(process, Pid).                                 

#Ref<0.0.0.255>

45>  Pid ! {self(),2}, F().                                          

receive....2

receive.. Pid=<0.59.0>..s="2"

{integer_to_list,"2"}

46>  Pid ! {self(),3}, F().

receive....3

receive.. Pid=<0.59.0>..s="3"

{integer_to_list,"3"}

47>  Pid ! {self(),a2}, F().                                         

receive....a2

{'DOWN',#Ref<0.0.0.255>,process,<0.89.0>,

        {badarg,[{erlang,integer_to_list,[a2]},

                 {testmonitor,hello3,0}]}}

 

=ERROR REPORT==== 28-Nov-2012::18:55:46 ===

Error in process <0.89.0> with exit value: {badarg,[{erlang,integer_to_list,[a2]},{testmonitor,hello3,0}]}

 

48>  Pid ! {self(),3}, F(). 

timeout

49>