Hello all,<br><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><span class="status-body"><span class="entry-content"> [ 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></span></span><br>A BIF along the lines of name() that returned the name would avoid the overhead of cycling through the process list in the above code. Roberto Ostinelli added that returning {global|local, Name} would be good, not sure how to do that.<br>
<br>To that end I've started trying to put together a function to do that, but I don't have my head around the Erlang sources yet so I'd appreciate help on the following:<br><br>1) Is there a BIF already that does this?<br>
2) Is this the correct way?<br>3) How do I return an Eterm value of 'none'?<br>4) How do I hook the function in as a BIF?<br>5) How would I make it so it returns {local|global, Name} instead of just Name?<br><br>What I've got so far is:<br>
<br><ol><li class="li1"><div class="de1">Eterm erts_thr_self_name(void) {</div></li><li class="li2"><div class="de2"> struct process * self_info = erts_get_current_process();</div></li><li class="li1"><div class="de1">
struct reg_proc * self_reg_info = self_info->reg;</div></li><li class="li2"><div class="de2"> if (self_reg_info != NULL) { /* ie if we're actually registered */ </div></li><li class="li1"><div class="de1">
Eterm name = self_reg_info->name;</div></li><li class="li2"><div class="de2"> return name;</div></li><li class="li1"><div class="de1"> }</div></li><li class="li2"><div class="de2">
else {</div></li><li class="li1"><div class="de1"> return /* Where to find 'none' Eterm value?? */</div></li><li class="li2">
<div class="de1"> }</div>
</li><li class="li2">
<div class="de1">}</div>
</li></ol>For convenience it's also at pastebin: <a href="http://pastebin.com/m2e5816e6">http://pastebin.com/m2e5816e6</a><br><br>Any help much appreciated,<br><br>=Bill.Barnhill<br><br><div class="syntax"><div class="text" style="font-family: monospace;">
<div style="text-align: left;"><br></div></div></div>