2

I have a multi-threaded application running on linux. In an event of a crash, say SIGSEGV, the handler is invoked. What will be the state of other threads in the process when the handler is executing? Will the threads be still running?

Anirudh Jayakumar
  • 1,171
  • 3
  • 15
  • 37
  • If the application crashes, the entire process crashes (thus, the threads also terminate). Threads are all in one process. Using `fork()` creates multiple processes. – RageD Mar 19 '13 at 15:54
  • 1
    @RageD No, if the signal is caught with a signal handler, the process isn't killed. – Ben Mar 19 '13 at 16:03
  • see [this question](http://stackoverflow.com/questions/5282099/signal-handling-in-pthreads) for a closely related topic. – didierc Mar 19 '13 at 16:14
  • @Ben: I read over the fact that he was using a signal handler. Thanks. – RageD Mar 19 '13 at 16:58

1 Answers1

3

The SIGSEGV signal is a synchronous signal. It is delivered to the thread (and to only that thread, not the process as a whole) that caused the invalid memory access.

See here for detailed information. Here is an excerpt from he linked document:

A signal may be generated (and thus pending) for a process as a whole (e.g., when sent using kill(2)) or for a specific thread (e.g., certain signals, such as SIGSEGV and SIGFPE, generated as a consequence of executing a specific machine-language instruction are thread directed, as are signals targeted at a specific thread using pthread_kill(3)). A process-directed signal may be delivered to any one of the threads that does not currently have the signal blocked. If more than one of the threads has the signal unblocked, then the kernel chooses an arbitrary thread to which to deliver the signal.

meyumer
  • 5,063
  • 1
  • 17
  • 21