Difference between PID and TID

后端 未结 4 668
刺人心
刺人心 2020-11-30 22:42

What is the difference between PID and TID?

The standard answer would be that PID is for processes while TID is for threads. However, I have seen that some commands

4条回答
  •  死守一世寂寞
    2020-11-30 23:16

    pid and tid are the same except when a process is created with a call to clone with CLONE_THREAD (per the man pages of gettid). In this case, you get a unique thread id but all threads belonging to the same thread group share the same process id.

    However, I also recall reading (though I cant find the source) that the values returned from getpid may be cached.

    [UPDATE] See the NOTES section here for a discussion on the effects of caching pids.

提交回复
热议问题