3

Assume a multi-threaded application, with a signal handler defined in it.

Now if a signal is delivered to the PROCESS, and signal handler is invoked - My doubt is what happens to other threads during the period signal handler is running. Do they keep running, as if nothing has happened or they are suspended for that period .. or ...?

Also if someone can tell me WHY to justify the answer?

merlin2011
  • 71,677
  • 44
  • 195
  • 329
ultimate cause
  • 2,264
  • 4
  • 27
  • 44

2 Answers2

4

The specification is pretty clear how signals and threads interact:

Signals generated for the process shall be delivered to exactly one of those threads within the process which is in a call to a sigwait() function selecting that signal or has not blocked delivery of the signal.

As the signal is delivered to exactly one thread, other threads are unaffected (and keep running).

cmeerw
  • 7,176
  • 33
  • 27
1

The threads are independent: a signal from one thread to a second thread will not affect any of the others. The why is because they are independent. The only reason why it would affect the others is if the signal handler of the thread in question somehow interacts with other threads.

user472875
  • 3,115
  • 4
  • 37
  • 68
  • Thanks. I think my question statement was not clear enough. Lets say the signal was delivered to process, and NOT to any specific thread. Is the answer still same? – ultimate cause Nov 12 '10 at 19:36
  • IIRC (although I may be wrong) an external signal to the process will be sent to all threads, so you need to set handlers for all threads that will need to respond to the signal or set an ignore state to ignore the signal. All threads which have an ignore will continue running normally, whereas any threads with handlers, will begin handling the signal. – user472875 Nov 12 '10 at 19:58
  • AFAIK, signals are process specific entities. If a signal is delivered to a process, to execute the code in signal handler, it would need a thread - Now which thread should execute signal handler - this choice of thread is arbitrary and unspecified. So after I chose one out of many others, all others should get suspended .. Isn't it ? What do you say ? – ultimate cause Nov 12 '10 at 20:11