Michaila
Michaila

Reputation: 31

pthread_kill kills not just a thread but the whole program

I am using int s=pthread_kill(thread_arr[t], 9); to send the SIGKILL signal to the thread that is in the t place of thread_arr, but instead of killing this exact thread my whole program is being killed. Can anyone tell me if I am doing something wrong?

Upvotes: 2

Views: 3629

Answers (1)

Richard St-Cyr
Richard St-Cyr

Reputation: 995

I think the answer is in the man page for pthread_kill:

Signal dispositions are process-wide: if a signal handler is installed, the handler will be invoked in the thread, but if the disposition of the signal is "stop", "continue", or "terminate", this action will affect the whole process.

The disposition of SIGKILL is to terminate the process, and the signal can't be caught, blocked or ignored.

I would suggest using a different signal, and having the thread receiving the signal stop itself, instead of using

Upvotes: 2

Related Questions