对于运行的系统来说,很多情况下,需要检测进程和服务是否在运行,也要允许我们可以暂定和恢复进程与服务,sys模块提供了一组很有用的方法,简单的介绍下:
1. get_status(Name,Timeout) 查看指定进程名的运行状态
- (ygzj_game2@127.0.0.1)41> sys:get_status(mod_carnival,1000).
- {status,<0.642.0>,
- {module,gen_server},
- [[{rand_to_process,1},
- {random_seed,{3611,14663,29715}},
- {'$ancestors',[yg_server_sup,<0.47.0>]},
- {'$initial_call',{mod_carnival,init,1}}],
- suspended,<0.55.0>,[],
- [{header,"Status for generic server mod_carnival"},
- {data,[{"Status",suspended},
- {"Parent",<0.55.0>},
- {"Logged events",[]}]},
- {data,[{"State",{carnival_state,2068003,<<>>,0}}]}]]}
2.suspend(Name,Timeout) 暂停(挂起)进程和服务
- (ygzj_game2@127.0.0.1)40> catch sys:suspend(mod_carnival,1000).
- ok
- (ygzj_game2@127.0.0.1)43> sys:get_status(mod_carnival,1000).
- {status,<0.642.0>,
- {module,gen_server},
- [[{rand_to_process,1},
- {random_seed,{3611,14663,29715}},
- {'$ancestors',[yg_server_sup,<0.47.0>]},
- {'$initial_call',{mod_carnival,init,1}}],
- suspended,<0.55.0>,[],
- [{header,"Status for generic server mod_carnival"},
- {data,[{"Status",suspended},
- {"Parent",<0.55.0>},
- {"Logged events",[]}]},
- {data,[{"State",{carnival_state,2068003,<<>>,0}}]}]]}
3. resume(Name,Timeout) 恢复被挂起(暂停)的服务和进程
- (ygzj_game2@127.0.0.1)44> catch sys:resume(mod_carnival,1000).
- ok
- (ygzj_game2@127.0.0.1)45> sys:get_status(mod_carnival,1000).
- {status,<0.642.0>,
- {module,gen_server},
- [[{rand_to_process,undefined},
- {random_seed,{10979,6101,16140}},
- {'$ancestors',[yg_server_sup,<0.47.0>]},
- {'$initial_call',{mod_carnival,init,1}}],
- running,<0.55.0>,[],
- [{header,"Status for generic server mod_carnival"},
- {data,[{"Status",running},
- {"Parent",<0.55.0>},
- {"Logged events",[]}]},
- {data,[{"State",{carnival_state,2073234,<<>>,0}}]}]]}
这些系统函数,使我们对我们的进程具有更多的控制手段,赞一个。
最近好久没有写博客了,工作有些忙,精神状态也不是很好,像在走夜路一样,需要一点光,谁敢给我一点光么 ~_~!
阅读(1703) | 评论(0) | 转发(0) |