我遇到了一个 SIGPIPE 崩溃问题,我想记录它并尝试存在。
但我无法通过后续代码捕获 SIGPIPE。
我尝试使用“kill -s signal process”来验证我的代码,它适用于信号 SIGINT、SIGSTOP、SIGSEGV 和 SIGALRM。
但在 SIGPIPE 上失败了。
如果我在这里错过任何东西,请您告知。
void handle_pipe(int sig)
{
printf("SIG_PIPE happen, error code is %d", sig);
exit(0);
}
int main(int argc, char **argv)
{
struct sigaction action;
sigemptyset(&action.sa_mask);
action.sa_handler = handle_pipe;
action.sa_flags = 0;
//not work
sigaction(SIGPIPE, &action, NULL); //Not work with kill -13 process_id
//works well
sigaction(SIGINT, &action, NULL); //work with kill -2 process_id
sigaction(SIGSEGV, &action, NULL); //work with kill -11 process_id
sigaction(SIGALRM, &action, NULL); //work with kill -14 process_id
sigaction(SIGSTOP, &action, NULL); //work with kill -17 process_id
fooServer * pfooServer = new fooServer();
while(1)
{
pfooServer->DoEvents();
}
delete pfooServer;
}
我的环境是 Ubuntu 12.04 LTS