threads belonging to same group have thread group id tgid stored in kernel stack of that process,The identifier shared by the threads is the PID of the thread group leader , that is, the PID of the first lightweight process in the group
This is done to comply with POSIX standards that all threads of a multithreaded application must have the same PID.
regards
Pushparaj
cheng long <kevinclcn@xxxxxxxxx> wrote:
Hi,
As we know, Linux implements thread as process, and a thread is merely
a process that shares certain resources with other processes.
But why the threads print the same process id?
Code like this:
void* print_pid(void* noused)
{
printf("%u\n",getpid());
return NULL;
}
int main()
{
printf("%u\n",getpid());
pthread_t thread_id;
int ret=pthread_create(&thread_id, NULL, &print_pid, NULL);
if(ret != 0 ){
return 1;
}
pthread_join(thread_id, NULL);
return 0;
}
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Yahoo! India Answers: Share what you know. Learn something new. Click here
Send instant messages to your online friends - NOW