1

如何修改 SIGKILL 的信号处理程序的代码,以便重新定义 SIGKILL 的 acitin?

4

2 回答 2

2

你不能。
信号 SIGKILL 和 SIGSTOP 不能被捕获、阻止或忽略。在这里阅读更多

于 2014-09-12T02:19:32.607 回答
0

您需要定义一个函数来处理异常发生时:

#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

void ExceptionHandler(int sig)
{
    #define MAXSTACKSIZE (16)
    void *stackTraces[MAXSTACKSIZE];
    size_t size;

    // get void*'s for all entries on the stack
    size = backtrace(stackTraces, MAXSTACKSIZE);

    // do other stuffs of your own

    exit(1);
}

然后在您的主代码中注册该函数(您也可以注册其他类型的异常):

signal(SIGSEGV, ExceptionHandler);
signal(SIGTERM, ExceptionHandler);
signal(SIGINT, ExceptionHandler);
signal(SIGILL, ExceptionHandler);
signal(SIGABRT, ExceptionHandler);
signal(SIGFPE, ExceptionHandler);

希望有帮助

于 2014-09-12T02:18:48.013 回答