mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* what's the relationship between tgid, tid and pid ?
@ 2002-12-05 19:36 Hu, Boris
  2002-12-05 20:47 ` Roland McGrath
  0 siblings, 1 reply; 3+ messages in thread
From: Hu, Boris @ 2002-12-05 19:36 UTC (permalink / raw)
  To: NPTL list (E-mail); +Cc: Linux Kernel ML (E-mail)


Linux 2.5.49
NTPL 0.10

I learned from the kernel source. sys_getpid() returns tgid and 
sys_gettid() returns pid. Moreover, 
/kernel/source/fork.c
copy_process() 
771 if (clone_flags & CLONE_PARENT_SETTID)
772 if (put_user(p->pid, parent_tidptr))  // parent_tidptr is tid in struct
pthread
                                   ....
It seems tid = pid, while tgid is head pthread pid. 

But the following lines let me confused.
/kernel/source/fork.c
copy_process()              
893         p->tgid = p->pid;
894         p->group_leader = p;
every pthread_create()->sys_clone()->do_fork()->copy_process()
p->tgid will be overwritten every time?

any comments? thanks. 

  Boris
=========================
To know what I don't know
To learn what I don't know
To contribute what I know
=========================


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: what's the relationship between tgid, tid and pid ?
  2002-12-05 19:36 what's the relationship between tgid, tid and pid ? Hu, Boris
@ 2002-12-05 20:47 ` Roland McGrath
  2002-12-06 14:15   ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Roland McGrath @ 2002-12-05 20:47 UTC (permalink / raw)
  To: phil-list; +Cc: Linux Kernel ML (E-mail)

> It seems tid = pid, while tgid is head pthread pid. 

"tgid" is the PID of the whole POSIX.1 process.
"pid" is a per-thread PID-like number.

> But the following lines let me confused.

You didn't read the rest of the function to see where it's changed again.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: what's the relationship between tgid, tid and pid ?
  2002-12-05 20:47 ` Roland McGrath
@ 2002-12-06 14:15   ` Ingo Molnar
  0 siblings, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2002-12-06 14:15 UTC (permalink / raw)
  To: NPT library mailing list; +Cc: Linux Kernel ML (E-mail)


On Thu, 5 Dec 2002, Roland McGrath wrote:

> "tgid" is the PID of the whole POSIX.1 process.
> "pid" is a per-thread PID-like number.

there's a "PID number space" under Linux, and "PID types". Each PID type
allocates from the same base number space, but they can also share the
same PID, ie. are overlayed:

enum pid_type
{
        PIDTYPE_PID,
        PIDTYPE_TGID,
        PIDTYPE_PGID,
        PIDTYPE_SID,

the 'TGID' is the "process PID" as in POSIX.1. The 'PID' is the same for
standalone processes and for leader threads, it's different for threads.  
Furthermore, the PID is also globally unique, and is recognized by the
sys_tkill() interface - ie. you can send signals between threads of
different "processes". The 'PGID' is the process group PID. The 'SID' is
the session ID.

the kernel guarantees reference counting, ie. only when the last type
detaches a given number is it allocatable again. This is partly required
by semantics for things like the PGID and the SID, and it's simply handy
for things like the thread identificator.

	Ingo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-12-06 12:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-05 19:36 what's the relationship between tgid, tid and pid ? Hu, Boris
2002-12-05 20:47 ` Roland McGrath
2002-12-06 14:15   ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®