Querying gproc - how to get a list of registered names?

I’m using gproc to register processes, like this:

gproc:register_name({n, l, Name}, Pid)

…and now (for debugging) I want to get a list of registered names. I’ve found gproc:select(), but I cannot figure out how to use it.

How do I get a list of registered names from gproc?

1 Like

You should be able to query the gproc ets table directly.

ets:select(gproc, [{{{'_',{n,l,'$1'}},'_'},[],['$1']}]).

but according to tests you can get local names with

gproc:select({local,names},[{{{n,l,'_'},'_','_'},[],['$_']}]).
1 Like

Have you consulted the documentation?

Please let me know if there are errors in it.

BR, Ulf

Yes. I find it hard to understand. It could use some examples.

So, most simply:

Starting uwiger-gproc-1.0.1.
Started [gproc]
1> gproc:reg({n,l,{a,1}}).
true
2> gproc:reg({n,l,{a,2}}).
true
3> gproc:reg({p,l,{a,2}},value).
true
4> gproc:select([{ {{n,l,{a,'_'}},'_','_'}, [], ['$_'] }]).
[{{n,l,{a,1}},<0.125.0>,undefined},
{{n,l,{a,2}},<0.125.0>,undefined}]
5> gproc:select([{ {'_',self(),'_'}, [], ['$_'] }]).
[{{n,l,{a,1}},<0.125.0>,undefined},
{{n,l,{a,2}},<0.125.0>,undefined},
{{p,l,{a,2}},<0.125.0>,value}]

The select() logic operates on a logical view of the registry: {Key, Pid, Value}. The Context thing is admittedly confusing, but for normal use, you don’t have to worry about that.

BR,

Ulf

While playing around with creating some simple examples, I stumbled upon a bug

I won’t be working on this right now. Contribs are always welcome. :wink: