UD NightWish UD NightWish - 4 months ago 7
Linux Question

SIGSEGV handler can not exit

I registered a handler of

, using
to print some message then exit. The process prints the message but did not exit. It blocked before

Can't I use
to finish the process normally in the handler?

void sigsegv__handler(){
fprintf(stderr, "SIGSEGV , TID: %d,PID: %d\n", TEST_ID, getpid());

alk alk

Can't I use exit() to normal finish the process in the handler?

exit() should not be called from a signal handler as it isn't guaranteed to be async-signal-safe. Use _exit(), _Exit() or abort() instead.

That said, printf() should not be called from a signal handler for the same reason that applies to exit().

For a full list of functions being async-signal-safe or not please have look down on this pages:

Moreover, the moment a segmentation violation occured the program is unstable, or even broken, the stack may me smashed, so there is no guarantee that anything may be called at all from that moment on.