当前位置: 技术问答>linux和unix
Linux 收到信号11后,在程序退出处理时再次收到信号11,假死问题
来源: 互联网 发布时间:2017-05-23
本文导语: 本帖最后由 zhxingway 于 2014-07-09 21:00:26 编辑 程序在后处理函数中再次出现信号11,导致进程假死,只能使用kill -9 pid 来结束进程。。 请问是不是程序在收到A信号,作退出处理时,如果再次收到A信号,则会处于假...
请问是不是程序在收到A信号,作退出处理时,如果再次收到A信号,则会处于假死?能否在收到信号时忽略后处理中的错误而强行退出?
因为这时,还可以接收其它信号,但是程序并不能退出。
注:信号11表示 非法内存访问。
|
我的实验里,如果在11的处理函数中再次产生错误,就会直接被系统杀死。
$ ./main
Got signal 11
Segmentation fault (core dumped)
$ ./main
Got signal 11
Segmentation fault (core dumped)
#include
#include
#include
static void show_handler(int s)
{
printf("Got signal %dn", 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);
}
}
|
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?
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...
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...