[erlang-questions] supervisor:start_child

Gregory Haskins <>
Mon May 2 21:43:31 CEST 2011

On 5/2/11 2:30 PM, Martin Dimitrov wrote:
>> You can also "not register" them, either locally or globally.  In your
> child's start_link, use the gen_server/3 instead of gen_server/4.
> I do this but when using the same id for the specification, I receive
> already_started error. I believe both need to be unique but my question
> is why.

The supervisor ID is a "supref" name-space that uniquely identifies the
_childspec_, so that it may be later referred to with terminate_child(),
delete_child(), and restart_child().

The first parameter in gen_server:start_link/4 is a process namespace
(actually, two: global and local) that uniquely identifies the _pid_.

In both cases, the name given _must_ be unique, though you can opt not
to specify a name in the pid namespace by using gen_server/3.  As far as
I know, you must always specify a name in the supref namespace, though
you can use a throw-away value (like erlang:now()) if you don't ever
care to terminate/delete/restart that particular child (at least via the
supervisor module).

So to answer your question, they both must be unique simply because the
namespaces in question do not allow duplicate entries.  However, the
namespaces do not really relate to one another, and one of them is
optional (i.e. via use of gen_server/3).

Hope that helps,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110502/8a956403/attachment.bin>

More information about the erlang-questions mailing list