LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-07-2005, 11:18 PM   #1
rajsun
Member
 
Registered: Mar 2005
Posts: 61

Rep: Reputation: 15
POSIX Thread programming problem...


Hi all,
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.
RajSun.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serial port programming problem (Win32 VS POSIX) chanwing Programming 1 06-29-2005 11:17 AM
POSIX thread Programming msriram_linux Programming 4 11-21-2004 03:14 PM
POSIX thread Ivan Lee Programming 2 03-28-2003 03:54 AM
RT Posix thread permissions spaceape Programming 0 01-23-2003 08:50 AM
posix thread sulo Programming 1 02-28-2002 07:41 PM


All times are GMT -5. The time now is 06:11 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration