process id of threads in the same process
c, linux, pthreads
Solution
There's a terminology conflict here. It's true that each thread is a separate process as far as the Linux kernel is concerned. And therefore Linux assigns a new PID to each thread.
But that's not how POSIX works: according to POSIX all threads in a process should share the same PID. The Linux kernel calls this "Thread Group IDs" (TGID), and the getpid() function actually returns the TGID, in order to be POSIX-compliant.
Problem
The following code is for printing the process id of the 2 threads linux(ubuntu 14.04) ``` #include<pthread.h> #include<stdio.h> #include <unistd.h> void* thread_function (void* arg) { fprintf (stderr, "child thread pid is %d\n", (int) getpid ()); /* Spin forever. */ while (1); return NULL; } int main () { pthread_t thread; fprintf (stderr, "main thread pid is %d\n", (int) getpid ()); pthread_create (&thread, NULL, &thread_function, NULL); /* Spin forever. */ while (1); return 0; } ``` And the output is ``` main thread pid is 3614 child thread pid is 3614 ``` But shouldn't be the process id be different since GNU/Linux,threads are implemented as processes??