Get list of supervisor child_specs

Hello,

Is it possible to get a list of child_specs mapped to child_ids belonging to a given supervisor? I have looked at the docs and couldn’t find any function that would do that.

Thanks!

I guess it’s stored in the state of the supervisor, but I was wondering if there was a better way to get it than to parse the state.

:supervisor.which_children/1 is the traditional erlang method, I’d imagine there is a Supervisor.which_children/1 in Elixir too, but if not then just calling the erlang method is fine.

For note, if you want ‘just’ the spec and not the rest of the child information then you can iterate over :supervisor.get_childspec/2 too, but which_children is easier.

1 Like

Hmm, I wasn’t aware which_children/1 returned child_specs (hexdocs). But :supervisor.get_childspec/2 is interesting, I should look into that.

Edit: :supervisor.get_childspec/2 works very well for my use case, so will use that. Thanks @OvermindDL1!

1 Like