QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1399|回复: 5

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

[复制链接]
发表于 2003-8-3 18:14:16 | 显示全部楼层 |阅读模式
在&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的内容啊,不知是不是我理解错了,还请指教
发表于 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,  
回复

使用道具 举报

 楼主| 发表于 2003-8-4 21:00:03 | 显示全部楼层
那请问黑体的那两句话应该怎么理解.不太明白说的什么意思啊?哪位大侠给翻一下.多谢了
回复

使用道具 举报

发表于 2003-8-4 22:32:54 | 显示全部楼层
who can write chinese?   come on!
回复

使用道具 举报

发表于 2003-8-6 12:52:47 | 显示全部楼层

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

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

[quote:cfe13c39a8="z3518"] 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.

[/quote]

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

使用道具 举报

发表于 2003-8-6 22:24:21 | 显示全部楼层
almost correct. thx
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-16 09:53 , Processed in 0.038823 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表