Signal Handling In Pthread

62 views Asked by At

in signal header there was a signal and raise. Signal is used to capture the signal and the raise is used to sending signal to the caller parameter.

But in multithread programming that used the pthread, we can use pthread_kill to be able to sending signal to other thread, but how to receive signal that have been send through the pthread_kill call

1

There are 1 answers

0
John Bollinger On

how to receive signal that have been send through the pthread_kill call

In any of the ways that a signal can be handled generally.

pthread_kill() differs from kill() and raise() primarily in how the thread that will handle the signal is chosen. With pthread_kill(), the caller designates the thread (of the same process) to which the signal will be directed. With kill(), the caller chooses the process(es), but the system chooses which thread. With raise(), the signal will be directed to the thread that called raise(). None of that changes how the signal can or will be handled upon receipt by the chosen thread.

When a signal becomes pending on a given thread it will be handled either

  • synchronously, via sigwait() or sigwaitinfo(), for example; OR
  • asynchonously, by
    • running the signal-handler function, if any, registered for that signal via signal() or, better, sigaction(), OR
    • according to the default disposition for that signal

Note well that signal handler registrations are process-wide. There are various ways to influence which threads receive which signals, but you cannot configure different threads of the same process with different handlers for the same signal.