Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  How to get pid number in NIF code?

Guest
Posted: Wed Sep 28, 2011 2:57 am Reply with quote
Guest
Hi,
I'm writing some code need to get pid number in NIF library, so
how to do it? I cannot found any nif function relate with it!
Thanks very much.

.jovi
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist
Guest
Posted: Wed Sep 28, 2011 7:31 am Reply with quote
Guest
Are you looking for enif_self() [1]?

Regards,

[1] http://www.erlang.org/doc/man/erl_nif.html#enif_self

Le 28 sept. 2011
Guest
Posted: Wed Sep 28, 2011 7:53 am Reply with quote
Guest
On Wed, Sep 28, 2011 at 3:31 PM, Anthony Ramine <nox@dev-extend.eu> wrote:
> Are you looking for enif_self() [1]?
>
> Regards,
>
> [1] http://www.erlang.org/doc/man/erl_nif.html#enif_self

enif_self only return ErlNifPid, but I want to get pid number.
like pid is <0.32.0>, what I want to get is 32, is there any way to
get number? Thanks!

ErlNifPid* enif_self(ErlNifEnv* caller_env, ErlNifPid* pid)
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist
tonyrog
Posted: Wed Sep 28, 2011 8:48 am Reply with quote
User Joined: 12 Sep 2009 Posts: 43
I do not think there is a way to extract that number (except for a small hack, of course)

Care to tell the reason behind why you need it ?


/Tony





On 28 sep 2011, at 09:53, Jovi Zhang wrote:
Quote:
On Wed, Sep 28, 2011 at 3:31 PM, Anthony Ramine <nox@dev-extend.eu (nox@dev-extend.eu)> wrote:
Quote:
Are you looking for enif_self() [1]?
Quote:

Quote:
Regards,
Quote:


enif_self only return ErlNifPid, but I want to get pid number.
like pid is <0.32.0>, what I want to get is 32, is there any way to
get number? Thanks!

ErlNifPid* enif_self(ErlNifEnv* caller_env, ErlNifPid* pid)
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org (erlang-questions@erlang.org)
http://erlang.org/mailman/listinfo/erlang-questions



"Installing applications can lead to corruption over time.
View user's profile Send private message
Guest
Posted: Wed Sep 28, 2011 9:04 am Reply with quote
Guest
On Wed, Sep 28, 2011 at 4:48 PM, Tony Rogvall <tony@rogvall.se> wrote:
> I do not think there is a way to extract that number (except for a small
> hack, of course)
> Care to tell the reason behind why you need it ?
> /Tony
>

Hmm, I'm writing a NIF library to let erlang process communicate with
external hand. we call that as "hand", it is similar with erlang
process, but with different number reference, hand is range from
0-65535.

So in this NIF library I must remember the mapping of
"process<->hand", actually I only run this in one node, with process
like <0.X.0>,
which I only care about process number, that's why I want to get
process number, not whole pid structure.

Of course I can store all "ErlNifPid<->hand index", but that will
consume a lot of memory.

I think erts should provide API or macro for get process number for
some use case.
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist
Guest
Posted: Wed Sep 28, 2011 1:15 pm Reply with quote
Guest
Someone must correct if I am wrong here but I don't think that an ErlNifPid takes much space. As I understand it is not the whole process structure, just a reference to it. From erl_nif.h:

#ifdef HALFWORD_HEAP_EMULATOR
# define ERL_NIF_VM_VARIANT "beam.halfword"
typedef unsigned int ERL_NIF_TERM;
#else
# define ERL_NIF_VM_VARIANT "beam.vanilla"
typedef unsigned long ERL_NIF_TERM;
#endif

...

typedef struct
{
ERL_NIF_TERM pid; /* internal, may change */
}ErlNifPid;

But someone more knowledgeable should confirm this.

Robert

----- Original Message -----
> On Wed, Sep 28, 2011 at 4:48 PM, Tony Rogvall <tony@rogvall.se>
> wrote:
> > I do not think there is a way to extract that number (except for a
> > small
> > hack, of course)
> > Care to tell the reason behind why you need it ?
> > /Tony
> >
>
> Hmm, I'm writing a NIF library to let erlang process communicate with
> external hand. we call that as "hand", it is similar with erlang
> process, but with different number reference, hand is range from
> 0-65535.
>
> So in this NIF library I must remember the mapping of
> "process<->hand", actually I only run this in one node, with process
> like <0.X.0>,
> which I only care about process number, that's why I want to get
> process number, not whole pid structure.
>
> Of course I can store all "ErlNifPid<->hand index", but that will
> consume a lot of memory.
>
> I think erts should provide API or macro for get process number for
> some use case.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist
Guest
Posted: Wed Sep 28, 2011 6:35 pm Reply with quote
Guest
Yes, ErlNifPid is typically the size of one word. You can type cast it
to an integer type of equal size to get a "process number".

/Sverker, Erlang/OTP

Robert Virding wrote:
> Someone must correct if I am wrong here but I don't think that an ErlNifPid takes much space. As I understand it is not the whole process structure, just a reference to it. From erl_nif.h:
>
> #ifdef HALFWORD_HEAP_EMULATOR
> # define ERL_NIF_VM_VARIANT "beam.halfword"
> typedef unsigned int ERL_NIF_TERM;
> #else
> # define ERL_NIF_VM_VARIANT "beam.vanilla"
> typedef unsigned long ERL_NIF_TERM;
> #endif
>
> ...
>
> typedef struct
> {
> ERL_NIF_TERM pid; /* internal, may change */
> }ErlNifPid;
>
> But someone more knowledgeable should confirm this.
>
> Robert
>
> ----- Original Message -----
>
>> On Wed, Sep 28, 2011 at 4:48 PM, Tony Rogvall <tony@rogvall.se>
>> wrote:
>>
>>> I do not think there is a way to extract that number (except for a
>>> small
>>> hack, of course)
>>> Care to tell the reason behind why you need it ?
>>> /Tony
>>>
>>>
>> Hmm, I'm writing a NIF library to let erlang process communicate with
>> external hand. we call that as "hand", it is similar with erlang
>> process, but with different number reference, hand is range from
>> 0-65535.
>>
>> So in this NIF library I must remember the mapping of
>> "process<->hand", actually I only run this in one node, with process
>> like <0.X.0>,
>> which I only care about process number, that's why I want to get
>> process number, not whole pid structure.
>>
>> Of course I can store all "ErlNifPid<->hand index", but that will
>> consume a lot of memory.
>>
>> I think erts should provide API or macro for get process number for
>> some use case.
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@erlang.org
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>
>

_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Post received from mailinglist
Guest
Posted: Thu Sep 29, 2011 1:42 am Reply with quote
Guest
Hmm, understood, Thanks very much, I will store the ErlNifPid instead
of process number.

On Thu, Sep 29, 2011 at 2:35 AM, Sverker Eriksson
<sverker@erix.ericsson.se> wrote:
> Yes, ErlNifPid is typically the size of one word. You can type cast it to an
> integer type of equal size to get a "process number".
>
> /Sverker, Erlang/OTP
>
> Robert Virding wrote:
>>
>> Someone must correct if I am wrong here but I don't think that an
>> ErlNifPid takes much space. As I understand it is not the whole process
>> structure, just a reference to it. From erl_nif.h:
>>
>> #ifdef HALFWORD_HEAP_EMULATOR
>> #  define ERL_NIF_VM_VARIANT "beam.halfword" typedef unsigned int
>> ERL_NIF_TERM;
>> #else
>> #  define ERL_NIF_VM_VARIANT "beam.vanilla" typedef unsigned long
>> ERL_NIF_TERM;
>> #endif
>>
>> ...
>>
>> typedef struct
>> {
>>    ERL_NIF_TERM pid;  /* internal, may change */
>> }ErlNifPid;
>>
>> But someone more knowledgeable should confirm this.
>>
>> Robert
>>
>> ----- Original Message -----
>>
>>>
>>> On Wed, Sep 28, 2011 at 4:48 PM, Tony Rogvall <tony@rogvall.se>
>>> wrote:
>>>
>>>>
>>>> I do not think there is a way to extract that number (except for a
>>>> small
>>>> hack, of course)
>>>> Care to tell the reason behind why you need it ?
>>>> /Tony
>>>>
>>>>
>>>
>>> Hmm, I'm writing a NIF library to let erlang process communicate with
>>> external hand. we call that as "hand", it is similar with erlang
>>> process, but with different number reference, hand is range from
>>> 0-65535.
>>>
>>> So in this NIF library I must remember the mapping of
>>> "process<->hand", actually I only run this in one node, with process
>>> like <0.X.0>,
>>> which I only care about process number, that's why I want to get
>>> process number, not whole pid structure.
>>>
>>> Of course I can store all "ErlNifPid<->hand index", but that will
>>> consume a lot of memory.
>>>
>>> I think erts should provide API or macro for get process number for
>>> some use case.
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@erlang.org
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@erlang.org
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum