【问题标题】:is an ambiguous behaviour for sigsegv是 sigsegv 的模棱两可的行为
【发布时间】:2016-03-04 13:18:57
【问题描述】:

注意:当我提出类似raise(SIGSEGV); 的 SIGSEGV 时,SEGSEGV 被阻止,但在取消引用 NULL 指针或内存冲突时没有。这里有什么问题?

代码:

void sig_handler(int signo)
{
       psignal(signo,"i am in sig_handler\n");
}

int main()
{
    sigset_t intmask;
    int c = 0, *p = NULL;

    if((signal(SIGSEGV , sig_handler)) == SIG_ERR)
             perror("signal call is failed\n");
    if ((sigemptyset(&intmask) == -1) || (sigaddset(&intmask, SIGSEGV) == -1))    
          perror("Failed to initialize the signal mask");
    sigprocmask(SIG_BLOCK, &intmask, NULL);
    fprintf(stdout, "SIGINT signal blocked\n");
    c = *p;
}

【问题讨论】:

    标签: c linux segmentation-fault signals ipc


    【解决方案1】:

    sigprocmask() 的手册页有答案:

    如果在阻塞时生成 SIGBUS、SIGFPE、SIGILL 或 SIGSEGV,则结果未定义,除非信号是由 kill(2)sigqueue(3)raise(3) 生成的。

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 2012-06-09
      • 2011-09-07
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 2019-09-10
      相关资源
      最近更新 更多