Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting PID for a process running on a remote node

Tags:

erlang

I am new to Erlang and we are working on a small scale messaging server.

We are trying to build a process registry using Redis ( not planning to use existing once grpoc, global etc due to other business needs ) as a datastore ( store to hold user-id to "node | PID " mapping). When a process starts it register itself with Redis in the form user_id (key) and {node | pid } as value. ( pid is tored as string in redis)

example value inserted in redis are "user_abc", {one@mf, "0.37.0>"}

Now when I try to find PID for "user_abc" which is running in the cluster - i get {node and pid} as value on a remote node which in this case is {one@mf, "0.37.0>".

Question is how do we use {node, pid} details on remote node to connect to the process user_abc.

Thanks in advance for your help.

like image 224
tintin Avatar asked Sep 18 '25 20:09

tintin


1 Answers

You can get a "cluster wide" pid by parsing that pid on the remote node:

On node a:

(a@host)1> pid_to_list(self()).
"<0.39.0>"

On node b:

(b@host)1> Pid = rpc:call('a@host', erlang, list_to_pid, ["<0.39.0>"]).
<7101.99.0>
(b@host)2> Pid ! my_test.
my_test

On node a:

(a@host)2> flush().
Shell got my_test
ok

Note that the process might not be alive, so calling erlang:monitor/2 on it before talking to it might be a good idea.

like image 114
Adam Lindberg Avatar answered Sep 22 '25 21:09

Adam Lindberg