POSIX Thread programming problem...
I m using POSIX thread to write a small code in C. In this code : :
1-> I have initialized thread attribute to detachable. Then i have created threads useing the thread attribute. So that my thread will be independaent of each other.
2-> In the main i have used pthread_setcanceltype and pthread_setcancelstate function so that i can cancle the main thread asynchronously.
3-> Then from mainthread i have created two other threads.
Question is ::
Q1 :: First i ran the code, then from new console while my executable was running in previous console i keyed "ps -ax" to see the running processes. I found four processes of my executable name r running. I mean to say that instead of 3 process of my executable name(1 for main thread, 2 for aother created two threads) I got 4 process of my executable name. For further exeplanation --
Suppose the executable name of my code is : : a.out
then after runnig the executable :: ./a.out
i moved to new console, n keyed "ps -ax"
I saw ::
2249 r ./a.out
2250 r ./a.out
2251 r ./a.out
2252 r ./a.out
whereas 2249 is mainthread, 2251 is first thread and 2252 is second thread. This i got to know by displaying the process id of each threads (using :: printf("pid :: %u\n",getpid()); in main function and thread functions). But i could not make out from where 2250 processid came?
Q2 :: If i m trying to call exit(0) from thread function while main function is waiting for some input from user or busy in executin something then the entire process is not exiting. That is considering the above example 2249 process is running and 2250 process became zombi processand other two process with pid 2251, 2252 terminated. I could not understand the behaviour ?
All the threads of a process share the same process address space, then if any of the created thread calls exit() function the whole process should exit. But in this case whta is happening....
If any body has any information plz let me know....
Thanking u all.