通过脚本启动主管的问题 - Erlang [英] Problem with starting supervisor through script - Erlang

查看:102
本文介绍了通过脚本启动主管的问题 - Erlang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个OTP兼容的应用程序,我有一个gen_server和一个主管。另外我有一个脚本启动他们。

I have made an OTP compliant application where i have a gen_server and a supervisor. Also i have a script to start them.

我的脚本包含这样的东西。
erl -pa module_name / ebin -name abc @ hostname -setcookie test -s module_sup start_link()

My script contains something like this. erl -pa module_name/ebin -name abc@hostname -setcookie test -s module_sup start_link()

这不会启动主管。但是当我在模块中执行module_sup:start_link()时,它可以正常工作。

This does not start the supervisor. But when i do module_sup:start_link() inside the shell, it works.

另外当我做
erl -pa module_name / ebin -name abc @ hostname -setcookie test -s module_srv start_link()
即服务器,没有主管,服务器启动。

Also when i do erl -pa module_name/ebin -name abc@hostname -setcookie test -s module_srv start_link() i.e the server alone without the supervisor, the server gets started.

所以,我在这里做错了什么我们不允许以这种方式启动主管。

So, what am i doing wrong here. Are we not allowed to start supervisor in such a way.

任何帮助都将被高度评价。

Any help would be highly appriciated.

Thanx ,
Wilson

Thanx, Wilson

推荐答案

supervisor:start_link / 2 指向其呼叫进程的链接。当调用进程退出时,主管将被关闭。

supervisor:start_link/2 creates a link to its calling process. when that calling process exits, the supervisor is taken down with it.

erl -s module_sup start_link 正在启动主管,但是它被杀死,因为你的启动函数运行在自己的进程中,一旦函数退出就死亡。

erl -s module_sup start_link is starting the supervisor but it is killed because your start function runs inside its own process which dies once the function exits.

你可以用 spawn module_sup,start_link,[])。主管启动并立即死机。当您手动启动主管时,调用进程是shell。当shell退出时,它会杀死主管。

you can observe similar behavior with spawn(module_sup, start_link, []). the supervisor starts and gets killed immediately. when you manually start the supervisor, the calling process is the shell. when the shell exits, it will kill the supervisor.

通常顶级主管是由应用程序启动。

generally the top-level supervisor is meant to be started by an application.

这篇关于通过脚本启动主管的问题 - Erlang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆