ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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....