registering processes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

registering processes

Karel Van Oudheusden

I have a question on distributed computing.

I have implemented a distributed program on two computers: computer A
and computer B.  Computer A executes the local erlang compiled file
'A.beam' while computer B executes the file 'B.beam'.

'A.erl' is the source code version of 'A.beam'. 'B.erl' is the source
code version of 'B.beam'.

In 'B.erl' I have spawned a process and registered it under a name.  I
have done this by using the 'register(Name, Pid)' command.  This allows
processes on computer A to communicate with this specific process
located on computer B.
The command I used is:  {registeredName, PID} ! message
This works fine.

However, the following does not work:
When a process on computer A communicates with the registered process on
computer B, some new processes are spawned on computer B as a result.
These newly spawned processes (which are not registered) send their PID
to the processes on computer A. After some time, a process on computer A
tries to send a message to one of these newly spawned processes on
computer B by just using the PID of the latter:  PID ! message

This does not work and if I'm not mistaken, this is because PID's are
only local identifiers of processes.  Therefore I am wandering whether a
command similar to the following exists:  {otherNode(), PID} ! message
In which otherNode() gives the IP address of computer B.

Stated otherwise, how do I "register" processes that are spawned during
execution of the program, without having to define new names for all
these processes?


Reply | Threaded
Open this post in threaded view

registering processes

Francesco Cesarini
What you describe should work, as processes are unique within a network
of meshed Erlang nodes, so you should be able to use the Pid to send
messages to different nodes.

What is probably happening is that one of your newly spawned processes
is terminating (normally or abnormally) but you don't notice as no error
print outs occur. So when you try to send a message to it, it is just
thrown away.

I would suggest you use the debugger to monitor the well being of your
processes (On both nodes), and ensure that the receiver is alive when
you send the message to it.

You could also use proc_lib:spawn/3 to spawn your processes, causing
error print outs when they terminate.

Francesco Cesarini

Erlang/OTP consultant
Cellular: INT+44-7776 250381
ECN: 832-707192