Handle SIGSEGV on Linux?

I need to handle SIGSEGV in my Linux application. The reason is some kind of cleanup (3-partry lib), which must be done before generating a core dump. Moreover, cleaning should be performed in the context of the calling thread; it cannot be performed in the signal handler. Therefore, I plan a signal handler to transfer control to the calling thread after the cleanup is complete, and then use raise (SIGSEGV) to create a core dump.

The real problem seems that signal_handler cannot pass control to the calling thread, regardless of whether I use post_sem or some others. Any idea to handle this thing? Is it possible to capture a SIGSEGV and then in the SIGSEGV hander return to another thread to do some cleanup?

(SIGSEGV, signal_handler);

signal_handler () {... post_sem (); ...}

calling thread () {wait_sem (); clean_up (); ...}

+1
source share
3 answers

You want to clear after SIGSEGV (that is, a serious mistake) ... I find this a bit strange because: 1) if you debugged the application, you should leave everything intact for storage in the main file so that you can determine exactly what happened, and 2) if you have a release application for the client (let's say) well ... that should not be SIGSEGV :) (not my problem, anyway, just saying ..)

In section

, SIGSEGV , , ; os . , , - - setjmp()/longjmp() ( ).

, , SEGV, (.. , SEGV ..), .

+3

, SIGSEGV. , . , , SIGSEGV - , , .

, , ( ,...).

+2

, -, , , , .

, , , .

Instead, the program should, after registering the status information, either return to the default handler (and to the kernel dump, etc.), or call _exit and exit without any cleaning.

If you need to perform a cleanup to get started after a failure, do it the next time you start.

+1
source

All Articles