signal handling

后端 未结 3 601
天涯浪人
天涯浪人 2020-12-09 23:54

I\'m just playing with signal in Mac OS X.

Why does the following code not produce the default behavior of SIGSEGV after my signal handler has finished? Under Linux,

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 00:48

    According to POSIX:

    If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated while they are blocked the result is undefined, unless the signal was generated by the kill() function, the sigqueue() function, or the raise() function.

    Because SIGSEGV is blocked while in the SIGSEGV signal handler, the result is undefined in this case and any behavior is valid. If you don't want it to be blocked you could install the signal handler using sigaction() with the SA_NODEFER flag, or use sigprocmask() to unblock the signal within the signal handler.

提交回复
热议问题