[erlang-questions] How to get pid number in NIF code?
Wed Sep 28 20:35:11 CEST 2011
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".
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;
> # define ERL_NIF_VM_VARIANT "beam.vanilla"
> typedef unsigned long ERL_NIF_TERM;
> typedef struct
> ERL_NIF_TERM pid; /* internal, may change */
> But someone more knowledgeable should confirm this.
> ----- Original Message -----
>> On Wed, Sep 28, 2011 at 4:48 PM, Tony Rogvall <>
>>> I do not think there is a way to extract that number (except for a
>>> hack, of course)
>>> Care to tell the reason behind why you need it ?
>> 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
>> 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 mailing list
More information about the erlang-questions