[erlang-questions] excute code in the supervisor when a child crashes?

Dave Smith <>
Mon Oct 19 19:22:41 CEST 2009


You won't be able to do this sort of accounting work in a supervisor.
Typically this problem is solved by having a secondary process that
acts as an entry point to the supervisor (i.e. calls
supervisor:start_child) and maintains monitors on all processes. This
secondary process then does the necessary accounting work when the
child process exits.

The rationale for this approach is supervisors are system-critical
code and as such you really, really, REALLY don't want to introduce
bugs into them.  Processes and monitors are cheap (enough) in Erlang
that a secondary accounting process is a reasonable solution and lets
us avoid introducing new code into the supervision system.

Hope that helps...

D.

On Mon, Oct 19, 2009 at 10:12 AM, Pablo Platt <> wrote:
> Hi,
>
> I have a supervisor with simple_one_for_one.
> When I start children with supervisor:start_child I save the child pid in an ETS table
> so I'll be able to exchange messages between all the child processes.
>
> When a child crashes I need to delete his pid from the ETS table or it'll grow constantly and eat all my memory.
> Is it possible to execute code when a child crashes or terminates?
>
> Thanks
>
>
>


More information about the erlang-questions mailing list