Supervisor with gen_server

来源:互联网 发布:windows手机版主题 编辑:程序博客网 时间:2024/06/03 16:21

转载请注明,来自:http://blog.csdn.net/skyman_2001

 

当gen_server进程加到监督树里,要想让它的supervisor终止时回调该gen_server进程的terminate()(可以在terminate()函数里做些清理工作),可以:

1. 该gen_server进程设置了捕捉退出信号:erlang:process_flag(trap_exit, true);

2. 其supervisor的child specification的关闭策略是超时的整数值,而不是brutal_kill。

当1和2都满足时,supervisor关闭时,会回调该gen_server进程的terminate(Reason, State)函数,其中Reason是shutdown。

详见:http://stackoverflow.com/questions/4842871/erlang-dynamic-supervisor-start-gen-server