Can I stop(pause) pthread execution using pthread_kill
Asked Answered
R

1

5

Will a thread stop if I send it SIGTSTP signal? Or in other words will it behave like process on SIGTSTP and SIGCONT?

Thanks in advance.

Remington answered 15/6, 2012 at 7:55 Comment(0)
R
4

From `man 3p pthread_kill:

Note that pthread_kill() only causes the signal to be handled in the context of the given thread; the signal action (termination or stopping) affects the process as a whole.

So I'd say that you will stop the whole process, not just the thread.

Revisal answered 15/6, 2012 at 8:16 Comment(5)
okay, thats possible, since I cant find sigaction for pthreads. I'll do the test.Remington
read man 3p pthread_kill myself, it is obvious that I cant use pthread_kill to stop thread execution, its mainly for redirecting received signal.Remington
@Revisal I think you miss-interprited the doc here. I disagree. It will affect only the servant threads created by the main thread of the process. When it says it will affect the process , it is saying that the resource would be re-adjusted to the remaining threads in that process.Marceau
@JayD - I disaggree with your disagreement. The doc makes a distintion between the signal handling and the signal action. The handling, that is, the function called as a response of the signal, if any, is done by the thread; but the action, that is, terminate, coredump, stop or continue, is done by the process as a whole. (I don't see a thread coredumping, for example, while the rest of the process goes on).Revisal
I didn't do the test, but it feels like this is correct answer. Latter I might do the test.Remington

© 2022 - 2024 — McMap. All rights reserved.