Xiliang Song
Xiliang Song

Reputation: 11

could I modify the code of the signal handler of SIGKILL

How could I modify the code of the signal handler of SIGKILL so that I can redefine the acitin of SIGKILL?

Upvotes: 1

Views: 1040

Answers (2)

tristan
tristan

Reputation: 4332

You cannot.
The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. Read more here

Upvotes: 2

ivzeus
ivzeus

Reputation: 1

You need to define a function to handle when exceptions happens:

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

Then in your main code register that function (you can register with other type of exceptions as well):

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

Hope that helps

Upvotes: 0

Related Questions