Linux – what is the value range of thread and process id


fork and pthread_create will return a process id or thread id.

But I don't know the value range of these ids.

Now I want to make a lookup table, in each entry there is a item/field for thread id.
the structure of each entry is like:

 typedef struct {
   int seq;
   pthread_t tid;
 } entry_t;

I want to assign a value to an invalid tid to an entry when I don't get the tid of a thread(soon this field will be filled with a valid one, but before that the fill function will check whether the pid is valid or not). so, what is the value range of thread and process id?

Best Solution

The pthread_t type is completely opaque. You can only compare it for equality with the pthread_equal function, and there is no reserved value distinct from any valid thread id, though such a value will probably be added to the next version of the POSIX standard. As such, you'll need to store a second field alongside the thread id to track whether it's valid or not.