Killing a Child Thread

Thread Tools Search this Thread
Top Forums Programming Killing a Child Thread
# 1  
Old 05-29-2012
Killing a Child Thread

What is the best way for a parent to kill a child thread that has blocked on a command it cannot finish and will never read another line of its code? Will pthread_cancel() work with a thread that will never stop processing its current line of code? Thanks.
# 2  
Old 05-30-2012
Read cancellation point and then you will know if you can use pthread_cancel.
Threads The read system call is one of a lot of cancellation points.

BTW - threads are very different from a child process.

You can also invoke pthread_kill but other threads and the main thread can be affected unless threads all have enabled per-thread signal handling.
# 3  
Old 05-30-2012
Thanks, but what do you mean by "read cancellation point?"

One other matter, my tests show that if, by chance, the thread no longer exists when I call pthread_cancel, the parent will abend with a segfault. What signal might I trap with signal() to prevent this?
# 4  
Old 05-30-2012
Originally Posted by Brandon9000
Thanks, but what do you mean by "read cancellation point?"
As in reading, reading which you do, not the computer. Specifically, reading about cancellation points on the link he posted.
# 5  
Old 05-30-2012
I see. Thanks. I will.

One other thing, if I cancel a thread, I have to consider the possibility that there could be an unanticipated scenario in which the thread no longer exists at the instant when I cancel it, even if thought I was doing appropriate checking for existence. In a test I did, cancelling a non-existent thread caused a segfault which caused the parent to exit. I tried to trap signals to prevent the parent from abending using SIG_IGN, but it abended anyway. Do you know if such a thing is possible. I did work up a scheme which should prevent ever cancelling a non-existent thread, but I would feel more comfortable if that situation were covered.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Child killing parent process and how to set up SMF

Hello, A little background on what we are doing first. We are running several applications from a CLI, and not all of them are fully functional. They do on occasion core dump, not a problem. We are running a service that takes a screen scrape of those apps and displays them in a more user... (5 Replies)
Discussion started by: Bryan.Eidson
5 Replies

2. Shell Programming and Scripting

A script that kills previous instances of itself upon running not killing child processes

I'm likely going to explain this clumsily, so apologies in advance: I have the following script: #!/bin/bash pidPrefix="logGen" checkPrime () { if /sbin/ifconfig eth0:0|/bin/grep -wq inet;then isPrime=1;else isPrime=0;fi } killScript () { /usr/bin/find /var/run -name... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

3. Programming

Parent Thread Of Child Thread

Parent Thread Of Child Thread Suppose a process creates some threads say threadC and threadD. Later on each of these threads create new child threads say threadC1, threadC2, threadC3 etc. So a tree of threads will get created. Is there any way to find out the parent thread of one such... (1 Reply)
Discussion started by: rupeshkp728
1 Replies

4. Red Hat

Killing child daemon started by parent process

Hi All, Hope this is right area to ask this question. I have a shell script (bash) "", which contains few simple shell command which executes a "" (conatins code to execute a java server) as a daemon. Now what I want to kill this "" so that the server should... (2 Replies)
Discussion started by: jw_amp
2 Replies

5. Solaris

Killing a thread having a listener socket

Hi All I have a separate thread ListenerThread having a socket listening to info broadcasted by some remote server. This is created in my main thread. Because of requirements, once the separate thread is started I need to avoid any blocking function on the main thread. Once it comes to the... (2 Replies)
Discussion started by: manustone
2 Replies

6. UNIX for Advanced & Expert Users

Child Killing Parent

Hi all, I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts. My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
Discussion started by: mark007
4 Replies

7. UNIX for Advanced & Expert Users

killing all child processes

Hi, Is there a way I can kill all the child processes of a process, given its process id. Many thanks in advance. J. (1 Reply)
Discussion started by: superuser84
1 Replies

8. Shell Programming and Scripting

Killing child process in ksh

I have a script that (ideally) starts tcpdump, sleeps a given number of seconds, then kills it. When I do this for 10 seconds or and hour, it works fine. When I try it for 10 hours (the length I actually want) it just doesn't die, and will actually stick around for days. Relevant part of my... (1 Reply)
Discussion started by: upnix
1 Replies

9. Shell Programming and Scripting

killing a child process

I am calling another script from my main script and making it run in the background,based upon the value of the input provided by the user I want to kill the child process ,I have written this code timer.ksh & PID=$$ print "\n Do you wish to continue .. (Y/N) : \c " read kill_proc if ]... (4 Replies)
Discussion started by: mervin2006
4 Replies

10. Shell Programming and Scripting

killing a child process within a shell

Hi All, I have a written a script in korn shell for importing data into a oracle database. The shell invokes the import within the script. I want to kill this import (child process) . I tries using trap, but this does not kill the import even if i press cnt c. i have to login into other terminal... (2 Replies)
Discussion started by: yerics
2 Replies
Login or Register to Ask a Question

Featured Tech Videos