进程单向监控-Monitor
来源:互联网 发布:国家战略知乎 编辑:程序博客网 时间:2024/04/29 07:16
转载:http://www.cnblogs.com/me-sa/archive/2011/11/20/erlang0016.html
link方式可以建立进程之间的双向链接关系,我们可以通过monitor实现单向的监控,这在gen_server代码里面可以看到对应的例子
- erlang:monitor(process, Caller), %建立单向监控
- 被监控进程死掉发送的消息规格: {'DOWN',Mref,process,Pid,Reason}
- 解除监控:erlang:demonitor(Ref)
gen_server代码片段:
do_multi_call(Nodes, Name, Req, Timeout) ->
Tag = make_ref(),
Caller = self(),
Receiver =
spawn(
fun() ->
%% Middleman process. Should be unsensitive to regular
%% exit signals. The sychronization is needed in case
%% the receiver would exit before the caller started
%% the monitor.
process_flag(trap_exit, true),
Mref = erlang:monitor(process, Caller), %建立单向监控
receive
{Caller,Tag} ->
Monitors = send_nodes(Nodes, Name, Tag, Req),
TimerId = erlang:start_timer(Timeout, self(), ok),
Result = rec_nodes(Tag, Monitors, Name, TimerId),
exit({self(),Tag,Result});
{'DOWN',Mref,_,_,_} -> %接受监控消息
%% Caller died before sending us the go-ahead.
%% Give up silently.
exit(normal)
end
end),
Mref = erlang:monitor(process, Receiver),
Receiver ! {self(),Tag},
receive
{'DOWN',Mref,_,_,{Receiver,Tag,Result}} ->
Result;
{'DOWN',Mref,_,_,Reason} ->
%% The middleman code failed. Or someone did
%% exit(_, kill) on the middleman process => Reason==killed
exit(Reason)
end.
- 进程单向监控-Monitor
- 进程单向监控-Monitor
- erlang进程监控:link和monitor
- erlang进程监控:link和monitor
- erlang进程监控:link和monitor
- erlang进程监控:link和monitor
- Process Monitor监控目录 - 监控文件被哪个进程操作了。
- dubbo-monitor监控安装
- Process Monitor监控目录
- Druid Monitor监控
- android monitor tool (8.0 监控文件系统 添加哪个进程修改文件功能)
- Monitor进程Linux
- LoadRunner monitor WebSphere_LoadRunner 监控 WebSphere
- Oracle 索引监控(monitor index)
- Zookeeper Monitor集群监控开发
- Zookeeper监控之bigdata1taokeeper-monitor
- Oracle索引监控(monitor index)
- Process Monitor 监控文件访问
- 不要把领导当成客户
- extjs apply,applyif,override,extend 的区别
- UBOOT 移植操作(4)
- 删除用户时 提示this user does not belong to this group
- 学习,只有勤奋是不够的……
- 进程单向监控-Monitor
- UBOOT命令总结
- 当你的小弟说与你有代沟了
- 聊聊淘宝今天的诚信体系纠结
- PHP过滤post,get敏感数据
- ICE Demo
- tcpdump 用例
- 按键软件去抖动设计
- msgsnd()