Results 1 to 5 of 5
Hi dears,
I'm new member and it's glad to join our forums. Now i have some unclear points and still need your ideas.
As i know, each process in Linux ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-11-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
[Questions] Process ID, Thread ID & Multi-thread ID
Hi dears,
I'm new member and it's glad to join our forums. Now i have some unclear points and still need your ideas.
As i know, each process in Linux Kernel has a Process Descriptor to stores all information of that process, one of them is process id (pid) which is stored in pid field of process descriptor.
And thread is a component of process, i've read some open documents and it said that thread id is equal with process id.
> So it means process id is also thread id?
> And in case of multi-thread, all these thread own the same thread id?
> One more point, a parent process could raise more child processes, so these child processes have the pid sequentially by parent pid + 1?
It's first time i come to Linux Kernel so hope your help
Regards.
-------
- 08-11-2011 #2
So, every thread has a thread ID. The main thread of a program (the first thread)'s TID is the same as the process's PID. Future threads will have different TIDs than the PID.
When a new process is created, it is assigned a PID that is not currently in use. This is not guaranteed to be sequential, but I do not believe that it is guaranteed to be random, either. For instance, if a new process is created, but the next PID is currently in use as a TID by some thread in another process, it cannot be used as the PID for the new process, because its main thread's TID could not equal its PID.
Does that make sense?
- 08-12-2011 #3Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
Hi Cabhan,
< So, every thread has a thread ID. The main thread of a program (the first thread)'s TID is the same as the process's PID. Future threads will have different TIDs than the PID.>
Now i understand that only main thread's ID (TID) is equal with process ID (PID), other TIDs are different & not sequence.
- So do you know which way these threads are assigned TID?
- And which register stores these TIDs in Linux Kernel that we could log it out?
Regards.
-------Last edited by Liverpudlian; 08-12-2011 at 01:42 AM.
- 08-12-2011 #4
I do not know about how TIDs are assigned. In my experience, they are frequently sequential, but that may just be because many threads are created in rapid succession before anything else happens.
You can check the TIDs that a process has through the proc filesystem. The /proc/PID/task directory contains a directory for every TID. As an example, here is the entry for my firefox:
Code:alex@niamh:/proc/3211/task$ ls 11872 23349 3211 3293 3294 3295 3296 3303 3311 3312 3335 3344 3348 3364 3390 3391 3414 3422 3429 3442 3452 3457 3485 3486 3524
- 08-15-2011 #5Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
Thanks for your advice, Cabhan.
Maybe i will learn more to find out the answer.
By the way, do you know about ARM architecture? Now i'm research how QEMU could get the process id, thread ids in ARM environment.
Do you have any idea about it?
Regards.
-------


Reply With Quote
