Linux 收到信号11后,在程序退出处理时再次收到信号11,假死问题

zhxingway 2014-07-09 08:58:47
程序在后处理函数中再次出现信号11,导致进程假死,只能使用kill -9 pid 来结束进程。。


请问是不是程序在收到A信号,作退出处理时,如果再次收到A信号,则会处于假死?能否在收到信号时忽略后处理中的错误而强行退出?

因为这时,还可以接收其它信号,但是程序并不能退出。

注:信号11表示 非法内存访问。
...全文
852 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhxingway 2014-07-21
  • 打赏
  • 举报
回复
在AIX系统中如果信号处理函数中再次收到信号,则会假死,
  • 打赏
  • 举报
回复
SIGSEGV's default action is terminate+core, if your program hung up, then it's probably something else. One possibility is: did it occur on the child process and then the main process hung or vice versa?
  • 打赏
  • 举报
回复
consider this scenario: parent process is waiting for child to repsond, say waiting for reading data from child. parent is blocked and in sleep (Uninterruptible sleep, which means it can't handle signal and that's why you have to kill -9). Then child crashed. So OS inherits child as zombie and wait for parent to call waitpid, but it will never happen since parent is blocked... but for your program, I have no idea what happened...
zhxingway 2014-07-10
  • 打赏
  • 举报
回复
2楼的例子试过了,没有问题,不会假死。 3楼的意思是不是说,在子进程中发生信号11,然后主进程中的信号处理函数中再次发生信号11才会导致进程挂起?
colddown 2014-07-09
  • 打赏
  • 举报
回复
我的实验里,如果在11的处理函数中再次产生错误,就会直接被系统杀死。 $ ./main Got signal 11 Segmentation fault (core dumped)
#include <signal.h>
#include <errno.h>
#include <stdio.h>

static void show_handler(int s)
{
    printf("Got signal %d\n", s);
    *(char *)0 = 1;
}

int main()
{
    struct sigaction newhandler, oldhandler;
    sigset_t blocked;

    newhandler.sa_handler = show_handler;
    sigemptyset(&newhandler.sa_mask);
    newhandler.sa_flags = 0;

    if (sigaction(SIGSEGV, &newhandler, &oldhandler) != 0) {
        perror("sigaction");
        return;
    }
    *(char *)0 = 1;
    while (1) {
        sleep(1);
    }
}

23,114

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧