z3518 发表于 2003-8-3 18:14:16

关于ULK2里关于轻量级线程的描述,有两句话不太明白啊?

在&lt;<ULK2>&gt;95页中关于LINUX对线程的支持的时候有以下描述.

All descriptors of the lightweight processes in the same thread
group are collected in a doubly linked list implemented through the thread_group field of
the task_struct structure. The identifier shared by the threads is the PID of the first
lightweight process in the group; it is stored in the tgid field of the process descriptors. The
getpid( ) system call returns current-&gt;tgid instead of current-&gt;pid, so all the
threads of a multithreaded application share the same identifier. The tgid field has the
same value as the pid field, both for normal processes and for lightweight processes not
included in a thread group. Therefore, the getpid( ) system call works as usual for them.

前面的很好理解,说有一个给同一线程组的tgid给所有给同组的轻量级进程共享.getpid()返回tgid代替pid.后面粗体的总值部分就不太明白了.

而且我看2.4的源代码,getpid()返回的还是PID的内容啊,不知是不是我理解错了,还请指教

Dragonfly 发表于 2003-8-4 01:17:21

check kernel/timer.c

744 /**
745* sys_getpid - return the thread group id of the current process
746*
747* Note, despite the name, this returns the tgid not the pid.The tgid and
748* the pid are identical unless CLONE_THREAD was specified on clone() in
749* which case the tgid is the same in all threads of the same group.
750*
751* This is SMP safe as current->tgid does not change.
752*/
753 asmlinkage long sys_getpid(void)
754 {
755         return current->tgid;
756 }

so it returns tgid,:-D

z3518 发表于 2003-8-4 21:00:03

那请问黑体的那两句话应该怎么理解.不太明白说的什么意思啊?哪位大侠给翻一下.多谢了

Dragonfly 发表于 2003-8-4 22:32:54

who can write chinese?:-D come on!

xdwjack 发表于 2003-8-6 12:52:47

Re: 关于ULK2里关于轻量级线程的描述,有两句话不太明白啊?

我试着翻译一下吧,我也对这个研究不深,还请指教。

The tgid field has the
same value as the pid field, both for normal processes and for lightweight processes not
included in a thread group. Therefore, the getpid( ) system call works as usual for them.


无论是对于我们通常所说的进程来说,还是对于那些不在同一个线程组的轻量进程(线程)来说,tgid域和pid域的值总是相同的。所以虽然getpid()系统调用的值是从tgid得到的,但是没有关系,这个值和pid的值是相同的,也就相当于得到了pid的值。这样看来getpid()系统调用并不因为进程的类型不同而采取不同的工作方式,仍然as usual for them。

Dragonfly 发表于 2003-8-6 22:24:21

almost correct. thx
页: [1]
查看完整版本: 关于ULK2里关于轻量级线程的描述,有两句话不太明白啊?