根据 UNIX 高级编程文档,SIGFPE 信号终止程序并生成核心文件。
这是我的程序
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static void sig_fpe(int signo);
int
main()
{
int pid;
if(signal(SIGFPE, sig_fpe) == SIG_ERR)
printf("Signal error\n");
pid = 10;
pid = pid / 0;
exit(0);
}
static void
sig_fpe(int signo)
{
if(signo == SIGFPE){
printf("SIGFPE signal catch\n");
}
}
当我在 linux 机器上运行这个程序时,它会反复打印“SIGFPE signal catch”并且不会终止。样本输出为
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
SIGFPE signal catch
.
.
.
.
问题是什么?