erlang otp child workers

I'm trying to get an OTP supervisor to start child workers which will (eventually) connect to remote servers. I used Rebar to create a template test application and I'm trying to get the supervisor to fire off function 'hi' in module 'foo'. it compiles OK and runs: Eshell V5.8.5 (abort with ^G) 1> test_app:start(1,1). {ok,<0.34.0>} but when I try to start the

erlang otp童工

我试图让一个OTP主管启动将会(最终)连接到远程服务器的童工。 我使用钢筋来创建一个模板测试应用程序,我试图让主管在模块'foo'中激发函数'hi'。 它编译好并运行: Eshell V5.8.5 (abort with ^G) 1> test_app:start(1,1). {ok,<0.34.0>} 但是当我尝试启动工作人员时,会出现梨形状,并显示以下错误消息: 2> test_sup:start_foo(). {error,{badarg,{foo,{foo,start_link,[]},

server crashes when started over supervisor

So, i spent LOTS of time and still didn't find the answer. I have simple tcp server in gen_server, which accepts messages via telnet and print them in console: -module(st_server). -behaviour(gen_server). %% -------------------------------------------------------------------- %% Include files %% -------------------------------------------------------------------- %% ----------------------

服务器在通过主管启动时崩溃

所以,我花了很多时间,仍然没有找到答案。 我在gen_server中有一个简单的tcp服务器,它通过telnet接受消息并在控制台中打印它们: -module(st_server). -behaviour(gen_server). %% -------------------------------------------------------------------- %% Include files %% -------------------------------------------------------------------- %% ---------------------------------------------------------------

Erlang: Best way for a singleton gen

Setting: I want to start a unique global registered gen_server process in an erlang cluster. If the process is stopped or the node running it goes down, the process is to be started on one of the other nodes. The process is part of a supervisor. The problem is that starting the supervisor on a second node fails because the gen_server is already running and registerd globally from the first

Erlang:单身人士的最佳途径

设置: 我想在erlang集群中启动一个独特的全局注册gen_server进程。 如果进程停止或节点正在运行,则该进程将在其他节点之一上启动。 该过程是主管的一部分。 问题在于启动第二个节点上的管理引擎失败,因为gen_server已经在运行并从第一个节点全局注册。 问题(S): 是否可以检查进程是否已经全局注册到gen_server的start_link函数中,并且在这种情况下返回正在运行的进程的{ok, Pid}而不是启动一个新的gen_server实

How to reference previously started processes in an Elixir supervisor

I am starting a Supervisor that monitors two children. The second child needs a reference to the first. It seams like this should be possible because by using the one_for_rest strategy I can make sure that if the first dies the second is restarted. children = [ supervisor(SupervisorA, [arg1]), supervisor(SupervisorB, [arg2, ref_to_supervisor_a_process]), ] supervise(children, strategy: :o

如何引用Elixir主管中以前启动的流程

我开始监督两个孩子的主管。 第二个孩子需要参考第一个孩子。 它的接缝应该是可能的,因为通过使用one_for_rest策略,我可以确保如果第一次死亡,第二次重新启动。 children = [ supervisor(SupervisorA, [arg1]), supervisor(SupervisorB, [arg2, ref_to_supervisor_a_process]), ] supervise(children, strategy: :one_for_rest) 理想情况下,无需全球命名任一流程。 SupervisorA可以向Supervisor.start_link/3提供

Erlang supervisor termination behavior

I have what may be an unusual situation, an application that starts 2 top-level supervisors, eg, ... -behavior(application). ... start(_StartType, _StartArgs) -> sup1:start_link(), sup2:start_link(). They both have a {one_for_one, 0, 1} restart strategy. Their children implement a simple crash function that throws a bad_match error. To my question, if I call sup1_child1:crash() su

Erlang主管终止行为

我有可能是一个不寻常的情况,一个启动2个顶级主管的应用程序,例如, ... -behavior(application). ... start(_StartType, _StartArgs) -> sup1:start_link(), sup2:start_link(). 他们都有一个{one_for_one, 0, 1}重启策略。 他们的孩子实现了一个简单的crash函数,该函数抛出bad_match错误。 对于我的问题,如果我打电话给sup1_child1:crash() supervisor sup1将终止,但应用程序将继续运行(即主管sup2及其

How to check whether the process was restarted by supervisor?

To be more precise: I have a supervisor for dynamic number of children. I want it to use different init function when given child is added and started for the fist time than for all the restarts than will happen later. Optionally, I could use the same function, if it is possible for the process to discover that it was restarted. Technically, there are side effects that could be used to find

如何检查过程是否由主管重新启动?

更确切地说: 我有一个负责儿童动态数量的主管。 当给定的孩子被添加并在第一时间启动时,我希望它使用不同的初始化函数,而不是在以后会发生的所有重新启动。 或者,如果流程可能发现它已重新启动,则可以使用相同的功能。 从技术上讲, 有副作用可以用来确定一个过程是否由其主管重新启动,或者是否是第一次启动。 例如,您可以检查进程的PID并将其与主管的PID进行比较。 然而,这是丑陋的,容易出错的,并且与OTP原则

How to atomatically delete specs of terminated children in a dynamic supervisor

No knowledge of USB needed for this question, just described it as it is to make the example more conrete. I'm trying to implement a dynamic supervisor for specific devices on a USB bus. These devices have addresses and appear and disappear during the lifetime of the system. For each device I need a dynamic child for my supervisor. These children are transient, so once they crash or te

如何自动删除动态主管中已终止子女的规格

没有这个问题所需的USB知识,只是描述它是为了让这个例子更具针对性。 我正试图为USB总线上的特定设备实现动态管理器。 这些设备具有地址并在系统的生命周期中出现并消失。 对于每台设备,我都需要一位充满活力的孩子为我的主管。 这些孩子是短暂的,所以一旦他们崩溃或终止,我们不会重新启动他们(因为他们可能已经消失了)。 我有一个在特定时间扫描USB端口的进程,并生成我想要处理的USB设备的所有地址列表。 我

Cowboy on Erlang crashes on shutdown

I'm getting a lot of errors on shutdown of my Erlang vm related to my cowboy handlers. I've got a simple_one_for_one supervisor running a start_listeners() function that runs cowboy:start_http(). Everything starts, no errors, handles requests normally. If I shutdown the erlang VM, I get: [error] Supervisor bitter_rpc_sup had child bitter_rpc_http_id started with bitter_rpc_sup:star

Erlang上的牛仔在关机时崩溃

我在关闭与我的牛仔处理程序相关的Erlang虚拟机时遇到了很多错误。 我有一个运行start_listeners()函数的simple_one_for_one主管,它运行cowboy:start_http()。 一切开始,没有错误,正常处理请求。 如果我关闭了erlang虚拟机,我会得到: [error]主管bitter_rpc_sup的子bitter_rpc_http_id以bitter_rpc_sup开头:start_listeners()处于未定义的出口,原因在上下文中死亡shutdown_error 还有一些与牛仔进程有关

Supervising an ordinary process in Erlang/OTP supervisor behaviour

As far as I understand, a supervisor process can supervise a number of processes in Erlang/OTP behavioral model. That processes can be gen_server , gen_fsm, and gen_event . My question is that can an ordinary process become supervised by a supervisor process in Erlang/OTP? By ordinary process I mean a process that is not gen_server , gen_fsm , or gen_event . If so, how process specification

监督Erlang / OTP主管行为中的普通进程

据我所知,主管进程可以监督Erlang / OTP行为模型中的大量进程。 该进程可以是gen_server , gen_fsm,和gen_event 。 我的问题是,一个普通的进程是否可以通过Erlang / OTP中的主管进程来监督? 通过普通的过程,我的意思是一个不是gen_server , gen_fsm或gen_event 。 如果是这样,流程规格将如何? 我在下面尝试,但不起作用: Spec = {Id, {my_module, my_function, [Par1, ..., ParN]}, permanent, 5000, worker, [m

How to restart child with custom state using Erlang OTP supervisor behaviour?

I'm using OTP supervisor behaviour to supervise and restart child processes. However when the child dies I want to restart it with the same state it had before the crash. If I write my own custom supervisor, I can just receive {EXIT,Pid,Reason} message and act upon it. When using OTP supervisor behaviour however it is all managed by OTP and I have no control over it. The only callback fu

如何使用Erlang OTP主管行为重新启动具有自定义状态的子项?

我正在使用OTP主管行为来监督和重新启动子进程。 但是,当孩子死亡时,我想用崩溃前的相同状态重新启动它。 如果我编写自己的自定义主管,则可以收到{EXIT,Pid,Reason}消息并对其执行操作。 当使用OTP管理员行为时,它全部由OTP管理,我无法控制它。 我实现的唯一回调函数是init。 在这种情况下是否有任何标准方法? 如何自定义由otp supervisor动态重启的子项的状态? 如何使用OTP获得终止进程的Pid? 或者也许有可