0
votes

I need a supervisor who can start two kinds of childen.

the first is a supervisor child, like the supervisor, can i start a child with the same module like the supervisor?

For Example:

-module(test_sup).
-behaviour(supervisor).

-export([start_link/0]).
-export([init/1]).

start_link() ->
     supervisor:start_link({local,?MODULE}, ?MODULE, []).

init(_Args) ->
        RestartStrategy = {one_for_one, 10, 60},
        {ok, {RestartStrategy, 

        [{sup,
        {sup, start_link, []},
        permanent, infinity, supervisor, [sup]},

  ]}}.

in the supervisor module i init a child with the same module, is it possible?

the second kind of child is a normal worker, with a own module, this is not the problem. But can i starts dynamic this two different kinds in the supervisor module?

2
If a supervisor spawns itself, than you get an infinite tree of supervisors, right? Probably crashes the app when running out of memory. Seems rather useless. What do you want to accomplish?Ward Bekker
i want to make a index of a directory, for example i start the supervisor in a dir and for each subfolder i want to start a new supervisor process. And the supervisor of each folder starts a child process to index the files of the folder. it is a exercise from an courseuser2513102

2 Answers

1
votes

In your comment, you said that you want to start up a process for every subfolder you run into. OTP created the simple_one_for_one supervisor for that.

In the start_link of the worker process, you can supply the directory path you want the process to index as the argument.

You can look at my full text search engine tutorial for a working example of a simple_one_for_one supervisor.

0
votes

The suggestion of Ward is really the good one. You can have a look at this page: LearYousomeErlang : the count of application, it has a complete example of the pattern you should use