[erlang-questions] Request for help on creating BIF (or finding existing one)

=Bill.Barnhill xmlarchitect@REDACTED
Wed Mar 11 12:07:03 CET 2009


Thanks, the func you sent is interesting, and that solves the global|local
issue (which seems to be a 'global and local', not 'global or local'). Given
the process_info func, then is the C code I wrote the same as
process_info(self(), registered_name)?

Thanks,
=Bill.Barnhill


On Tue, Mar 10, 2009 at 7:15 PM, Ulf Wiger
<ulf.wiger@REDACTED>wrote:

> =Bill.Barnhill wrote:
>
>>
>> I was recently asked how to have a process get its registered name. AFAIK
>> there is no BIF for this. It can be accomplished via:
>> [ N || N <- global:registered_names(), global:whereis_name(N) == self()]
>> which will either return [] if it's not registered or [Name] if it is.
>>
>
> Here's a way to do it without BIFs, and with some peeking in
> global's innards:
>
> names(Pid) when is_pid(Pid) ->
>  Global = [{global,G} ||
>              {_, G} <- ets:lookup(global_pid_names, Pid)],
>  case process_info(Pid, registered_name) of
>    {registered_name, N} ->
>        [{local, N}|Global];
>    [] ->
>        Global
>  end.
>
>
> BR,
> Ulf W
>
>
> --
> Ulf Wiger
> CTO, Erlang Training & Consulting Ltd
> http://www.erlang-consulting.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090311/d4748f19/attachment.htm>


More information about the erlang-questions mailing list