troubleshooting Question

pthread, thread prints the same process id of mail thread.

Avatar of JRPrakash
JRPrakash asked on
Linux OS DevC
14 Comments1 Solution652 ViewsLast Modified:
Hello,
I have the following code snippet

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
void* t_function (void* arg)
{
fprintf (stdout, “child->  thread pid is %d\n”, (int) getpid ());

while (1);
return NULL;
}
int main ()
{
pthread_t thread_id;
fprintf (stdout , “main->  thread pid is %d\n”, (int) getpid ());
pthread_create (&thread_id, NULL, &t_function, NULL);


while (1);
return 0;
}


Here main, and  child thread both prints the pid  same value. How is that possible ?. As for as i know
in linux, a thread is as like as individual process, but only shares the process address space?.
I m trying to run in ubuntu linux kernel 2.6.   Any suggessions ??
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros