reeze/tipi

第八章第二节里面说到的getpid获取的不是pid而是tgid,怎么理解

Closed this issue · 3 comments

在Linux中叫进程ID,在系统调用fork期间生成,只是我们通过getpid返回的不是其pid字段,而是其线程组号tgid。

不是父进程中返回子进程的pid,在子进程中返回0吗?

这里的getpid作何理解呢?

c9n commented

You might be wondering why does getpid() return tgid, the thread group ID ? In normal processes, the TGID is equal to the PID. With threads, the TGID is the same for all threads in a thread group. This enables the threads to call getpid() and get the same PID.

@c9n 感谢!