ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If i want to kill the thread of a parent process, but its killing the whole parent process. This seems to be obvious thing as threads does not have different PIDs but before proceeding further, i would like you to read my first thread http://www.linuxquestions.org/questi...d.php?t=567347
So, as per this thread, i can see that doing ps -efm shows me that a different PID has been allocated to the thread. So, taking that PID i tried to kill it, but it was killing the parent process?
Can anyone tell me where i am doing wrong and then how can i achieve my objective?
pthreads programming requires a certain amount of cooperation between threads. There's cleanup code and other stuff going on under the hood that would get messed up if you were able simply to kill a thread.
The only way to kill a thread is, within your program, calling pthread_cancel(). Even then it's complex and often dangerous.
The best way in the long run is to write the code so that it cleanly does a pthread_exit() if it senses that you want it to stop.
Each individual thread in a program using pthreads is part of the same process (you can not signal individual threads). You have to code your program to do any thread management you want done.
So what you mean is that its a construct imposed by the kernel that we cant kill the pthreads just like that.
No, what I mean is that it's a detail of pthreads itself, for your own protection. If you were able to kill a thread, then the coordination between threads would be broken, and your program would misbehave.
No, what I mean is that it's a detail of pthreads itself, for your own protection. If you were able to kill a thread, then the coordination between threads would be broken, and your program would misbehave.
Each individual thread in a program using pthreads is part of the same process (you can not signal individual threads). You have to code your program to do any thread management you want done.
I agree with you. In fact, I was told the same thing by other members also. But, the problem is that since we can't catch SIGKILL so even if I want to implement my own thread killing mechanism, I am helpless
So, I just thought of consulting you guys. Anyways thanks a lot
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.