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)?<br>
<br>
Thanks,<br>
=Bill.Barnhill<br>
<br><br><div class="gmail_quote">On Tue, Mar 10, 2009 at 7:15 PM, Ulf Wiger <span dir="ltr"><<a href="mailto:ulf.wiger@erlang-consulting.com">ulf.wiger@erlang-consulting.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">=Bill.Barnhill wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
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:<br>
[ N || N <- global:registered_names(), global:whereis_name(N) == self()]<br>
which will either return [] if it's not registered or [Name] if it is.<br>
</blockquote>
<br></div>
Here's a way to do it without BIFs, and with some peeking in<br>
global's innards:<br>
<br>
names(Pid) when is_pid(Pid) -><br>
  Global = [{global,G} ||<br>
              {_, G} <- ets:lookup(global_pid_names, Pid)],<br>
  case process_info(Pid, registered_name) of<br>
    {registered_name, N} -><br>
        [{local, N}|Global];<br>
    [] -><br>
        Global<br>
  end.<br>
<br>
<br>
BR,<br>
Ulf W<br><font color="#888888">
<br>
<br>
-- <br>
Ulf Wiger<br>
CTO, Erlang Training & Consulting Ltd<br>
<a href="http://www.erlang-consulting.com" target="_blank">http://www.erlang-consulting.com</a><br>
</font></blockquote></div><br>