Why do processes started with :simple_one_for_one strategy appear to have :undefined id?

I’ve been wondering about this, why doesn’t Supervisor.which_children/1 (and underlying :supervisor.which_children/1 of course) return the names of the child processes? Is it an inherent limitation of BEAM or is it done for other reasons (performance)?

I know that the registered name of the process can be retrieved by getting the information about that pid:

iex(1)> [{_, pid, _, _}] = Supervisor.which_children MyApp.Simple.Supervisor
[{:undefined, #PID<0.823.0>, :worker, [MyApp.Simple.Worker]}]
iex(2)> Process.info(pid)[:registered_name]
:my_named_process
2 Likes

It is because in the case of a simple_one_for_one, the child specification will not list what processes will be started, but a template that will be used as blueprint for all started children of this Supervisor.

There can potentially multiple child processes be started from the same blueprint (and often this is the case), which means that returning an ID would be confusing (as it would not uniquely identify that specific process).

2 Likes

Thanks @Qqwy, your reply prompted me to read the documentation again, this time more carefully.

I have figured what was the problem - I misunderstood what the Supervisor.Spec.child_id in Supervisor.which_children/1 represents, for some reason I thought that it was the registered name of the child process, not the template used for spawning the process.

2 Likes