我可以修改SIGKILL的信号处理程序的代码吗



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

您不能
不能捕获、阻止或忽略信号SIGKILL和SIGSTOP。点击此处阅读更多

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

#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);

希望对有所帮助

最新更新