You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to regsiter some processes with a famliy name with gproc.
For this reason I created a gen_server that contain two function, the first one is to
handle registration and the second one is to lookup Pids of registered processes.
After that, I opnened two erlang consoles and I registered two processes with the same property
(each console request the server to register one process)
My server code is as follows:
I registered my processes with server_name:register(PID,<<"test">>)
and I lookup the pids with: server_name:getpids(PID,<<"test">>)
But when I tried to get the pids of my family processes (Basically I have to pull a list
with 2 pids) I got just one pid (each console just lookup the pid registered by him self
and not render the pid registered with the other console).
Thanks for your help.
Best Regards.
The text was updated successfully, but these errors were encountered:
hamdijmii1992
changed the title
Each process just return it's pid when performing lookup_pids
Each process just return it's own pid when performing lookup_pids
Jan 29, 2017
Have not tested your code yet but from what I see you are registering locally and doing lookups locally because of the l in gproc:reg_or_locate({p,l,Name}), and Pids = gproc:lookup_pids({p,l,Name}),. This means your properties are registered just within each node (the two consoles in your case I guess).
Try doing a global registration and lookup using g in place of l that is {p,l,Name} should be {p,g,Name}
If you know that you'll only register a name once, you can use gproc:reg/1. If you want the call to be tolerate repeated registrations of the same name, gproc:ensure_reg/1 works nicely:
I tried to regsiter some processes with a famliy name with gproc.
For this reason I created a gen_server that contain two function, the first one is to
handle registration and the second one is to lookup Pids of registered processes.
After that, I opnened two erlang consoles and I registered two processes with the same property
(each console request the server to register one process)
My server code is as follows:
`start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [],[]).
init([]) -> gproc:start_link(), {ok, []}.
%% Synchronous call
register(Pid, Name) ->
gen_server:call(Pid, {register, Name}).
getpids(Pid, Name) ->
gen_server:call(Pid, {getpids, Name}).
handle_call({register, Name}, _From, State) ->
gproc:reg_or_locate({p,l,Name}),
{reply, Name, State};
handle_call({getpids, Name}, _From, State) ->
Pids = gproc:lookup_pids({p,l,Name}),
{reply, Pids, State}.
handle_info(Msg, State) ->
io:format("Unexpected message: pn",[Msg]),
{noreply, State}.
terminate(normal, State) ->
ok.`
I registered my processes with
server_name:register(PID,<<"test">>)
and I lookup the pids with:
server_name:getpids(PID,<<"test">>)
But when I tried to get the pids of my family processes (Basically I have to pull a list
with 2 pids) I got just one pid (each console just lookup the pid registered by him self
and not render the pid registered with the other console).
Thanks for your help.
Best Regards.
The text was updated successfully, but these errors were encountered: