[erlang-questions] Pinging the great unknown
Wed May 18 23:12:54 CEST 2016
On Wed, May 18, 2016 at 04:40:36PM -0400, Donald Steven wrote:
> Hi all,
> Simple newbie question for someone just learning. I'm getting the hang of sending and receiving messages work and pids, but how does a process ping a message into the great unknown that says basically: "Hello out there, I'm here, I exist..." if you don't know what if any processes are 'out there' to actually receive a message?
One approach: Process A (the receipient) registers itself with
register/2, using an atom as a name. Process B (the sender) uses the
same atom to look up the pid of A, with whereis/1. So, the initial
"connection" between the two comes from the programmer knowing that
process A registers under a particular name, and then telling process
B to use that name. There's a simple built-in registry (register/2,
whereis/1), or there are more complex third-party registries (like
Another approach: Process A starts. It starts process B, passing in
its own pid as a parameter. Alternatively, process C could have
started both A and B, getting the pid of A after it's running, and
passing that to B as a parameter on startup.
The first approach is more typical, particularly in the case where
process A is a server of some kind.
Hugo Mills | Be pure.
carfax.org.uk | Be vigilant.
http://carfax.org.uk/ | Behave.
PGP: E2AB1DE4 | Torquemada, Nemesis
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 836 bytes
Desc: Digital signature
More information about the erlang-questions