Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

erlang: anything like name_for_pid()?

Tags:

erlang

Is there a way to get a registered name if you have a PID?

like image 832
mwt Avatar asked Oct 19 '10 23:10

mwt


People also ask

What is Erlang processes?

Erlang processes are lightweight, operate in (memory) isolation from other processes, and are scheduled by Erlang's Virtual Machine (VM). The creation time of process is very low, the memory footprint of a just spawned process is very small, and a single Erlang VM can have millions of processes running.

How do I terminate a process in Erlang?

A process can terminate itself by calling one of the BIFs exit(Reason), erlang:error(Reason), erlang:error(Reason, Args), erlang:fault(Reason) or erlang:fault(Reason, Args). The process then terminates with reason Reason for exit/1 or {Reason,Stack} for the others.

Which module is used to spawn processes manually in Erlang?

The Erlang BIF spawn is used to create a new process: spawn(Module, Exported_Function, List of Arguments).

What does spawn do in Erlang?

spawn() creates a new process and returns the pid. The new process starts executing in Module:Name(Arg1,...,ArgN) where the arguments are the elements of the (possible empty) Args argument list. There exist a number of different spawn BIFs: spawn/1,2,3,4.


1 Answers

I'm assuming you want this for some kind of debugging/introspection purpose and not for general use in your code:

erlang:process_info(Pid, registered_name).

Gives you [] if the process doesn't have a locally registered name, and {registered_name, Name} if there is one.

like image 125
archaelus Avatar answered Oct 11 '22 11:10

archaelus