Understanding Pthreads

前端 未结 4 1218
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 20:07

I came across a concept in Advanced Linux Programming. Here\'s a link: refer to 4.5 GNU/Linux Thread Implementation.

I\'m clear wit

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 21:04

    All threads created by a process belong to this one process by defintion. To get this one process' process-id use getpid(), no matter from which of the process' threads.

    The author of the document linked is correct, that under Linux (p)threads are implemented as distinct processes sharing the same address space as the one process they belong to. The latter however is not reflected by getpid(), the author of the linked document is wrong with this assumption.

    To get the process-id of the distinct process created for a single thread use (the Linux specific) gettid()*1.


    *1: Please note that the glibc does not provide a wrapper to this function call. Use syscall() to invoke it.

提交回复
热议问题