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.

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.

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?

As in reading, reading which you do, not the computer. Specifically, reading about cancellation points on the link he posted.

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.