title: Why two threads in NPTL have different pid in Ubuntu12.04
body: <p>I tested some code in Ubuntu 12.04 LTS server x64(3.2 kernel), which I think is using NPTL.</p>
  
  <p>when I run</p>
  
  <pre><code>$ getconf GNU_LIBPTHREAD_VERSION
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>NPTL 2.15
  </code></pre>
  
  <p>The following is the test code. I compiled it with gcc -g -Wall -pthread</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;pthread.h&gt;
  
  void *func1(void *arg)
  {
      printf("func1:[%d]%lu\n", getpid(), pthread_self());
      for(;;);
      return (void *)0;
  }
  
  int main(void)
  {
      printf("main:[%d]%lu\n", getpid(), pthread_self());
  
      pthread_t tid1;
      pthread_create(&amp;tid1, NULL, func1, NULL);
      void *tret = NULL;
      pthread_join(tid1, &amp;tret);
  
      return 0;
  }
  </code></pre>
  
  <p>when I run the program, it seems all to be expected: <b>two threads have the same pid</b></p>
  
  <pre><code>$ ./a.out
  main:[2107]139745753233152
  func1:[2107]139745744897792
  </code></pre>
  
  <p>but in htop (a top like tool, you can get it by apt-get) I see this: <b>two threads have different pid</b></p>
  
  <pre><code>PID  Command
  2108 ./a.out
  2107 ./a.out
  </code></pre>
  
  <p>If I kill the pid <b>2108</b>, the process will be killed</p>
  
  <pre><code>$ kill -9 2108
  
  $./a.out
  main:[2107]139745753233152
  func1:[2107]139745744897792
  Killed
  </code></pre>
  
  <p>And if I run the program through gdb, I can see <b>LWP</b></p>
  
  <pre><code>[Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
  main:[2183]140737354069760
  [New Thread 0x7ffff77fd700 (LWP 2186)]
  func1:[2183]140737345738496
  </code></pre>
  
  <p>I think NPTL's threads share one PID and LWP is for LinuxThreads before kernel 2.6.
  The Above seems that NPTL is still using LWP under.
  Am I right? I want to know the truth about NTPL and LWP.</p>
  
  <p>Thanks.</p>