2013/5/11 Shuo Chen <
gian...@gmail.com>:
> identity. 用 gettid(2) 拿到的就是你说的那两个“号”。
>
你确定? getpid(2)拿到的是进程号,在Linux上其实是
thread group identifier (TGID),gettid(2) 拿到的是线程号,TID。
单独一个拿不到两个号的。
clone(2)里面明确解释到:
Thread groups were a feature added in Linux 2.4 to
support the POSIX threads notion of a set of threads
that share a single PID. Internally, this shared PID is
the so-called thread group identifier (TGID) for the thread
group. Since Linux 2.4, calls to getpid(2) return the TGID
of the caller.
The threads within a group can be distinguished by their
(system-wide) unique thread IDs (TID). A new thread's
TID is available as the function result returned to the caller
of clone(), and a thread can obtain its own TID using gettid(2).
至少在用户空间,它们是没有明确的对应关系的,所以你只能调用
它们两个来获取这两个ID。