试了下linux下的signal函数出错了,求大神解释下啊。 财富值15

2016-10-13 14:51发布

linux 的自定义signal处理函数为什么会不停的触发呀?
如下图所示,除以0的情况下,会触发SIGFPE信号,调用自定义的sig_fpe函数;那么为什么会不停的触发这个函数呀。不应该是只触发一次吗?

`   1 #include <iostream>   2 #include <unistd.h>   3 #include <linux/types.h>   4 #include <sys/types.h>   5 #include <signal.h>   6 using namespace std;   7 static void sig_fpe(int signo){   8     cout<<"sig fpe error "<<signo<<endl;   9 }  10   11 int main(){  12     signal(SIGFPE , sig_fpe);  13     int m = 1000/2;                                                                                                  14     return 0;     15 }               `
3条回答

According to POSIX, the behavior of a process is undefined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated by kill(2) or raise(3). Integer division by zero has undefined result. On some architectures it will generate a SIGFPE signal. (Also dividing the most negative integer by -1 may generate SIGFPE.) Ignoring this signal might lead to an endless loop.

一周热门 更多>