Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 421
misteryes Avatar asked May 17 '13 00:05

misteryes


People also ask

What is process ID and thread ID?

The thread ID of the initial (main) thread is the same as the process ID of the entire process. Thread IDs for subsequently created threads are distinct. They are allocated from the same numbering space as process IDs. Process IDs and thread IDs are sometimes also referred to collectively as task IDs.

What is the maximum limit of PID?

On 32-bit platforms, 32768 is the maximum value for pid_max.

How many numbers is a PID?

What is a Parcel Identifier (PID)? A PID is a nine-digit number that uniquely identifies a parcel in the land title register of British Columbia.

What is the length of PID?

The PID is also called a cone. The measurement between the target area and the receptor is called the target-‐receptor distance. The target-‐receptor distance depends on the length of the PID. It may be 8, 12, or 16 inches long.


2 Answers

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.

like image 101
R.. GitHub STOP HELPING ICE Avatar answered Sep 27 '22 20:09

R.. GitHub STOP HELPING ICE


The max value of pid is changeable, in default it is 32768, which is the size of the max value of short int.And, it can compatible with UNIX of early version.

You can see and change it in /proc/sys/kernel/pid_max.

BTW,

Process ID 0 is usually the scheduler process and is often known as the swapper. No program on disk corresponds to this process, which is part of the kernel and is known as a system process. Process ID 1 is usually the init process and is invoked by the kernel at the end of the bootstrap procedure. The program file for this process was /etc/init in older versions of the UNIX System and is /sbin/init in newer versions. This process is responsible for bringing up a UNIX system after the kernel has been bootstrapped. --APUE

The tid has significance only within the context of the process to which it belongs. In different famlies of UNIX, the pthread_t is not the same type,such as

Linux 2.4.22 uses an unsigned long integer for the pthread_t data type. Solaris 9 represents the pthread_t data type as an unsigned integer. FreeBSD 5.2.1 and Mac OS X 10.3 use a pointer to the pthread structure for the pthread_t data type. --APUE

So you can't simply tell its scope .

But threads_max presents how many threads in a process at most,you can see and change it in /proc/sys/kernel/threads-max.

like image 20
vvy Avatar answered Sep 27 '22 20:09

vvy