How could I modify the code of the signal handler of SIGKILL so that I can redefine the acitin of SIGKILL?
Asked
Active
Viewed 905 times
1
-
Just at the begainning! I don't know how to deal with it. – Xiliang Song Sep 12 '14 at 03:15
-
First, search the kernel source for functions related to signal handling and delivery. Then, read the source code until you understand how it works. Then, make your modification. – Peter Sep 12 '14 at 13:06
2 Answers
2
You cannot.
The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
Read more here

tristan
- 4,235
- 2
- 21
- 45
-
Could I modify the kernel code related to SIGKILL handler and recompile the kernel to redifine my own ation? – Xiliang Song Sep 12 '14 at 03:05
-
sure you could but why do you need this? To have a process always running? – tristan Sep 12 '14 at 03:18
-
Well, now I'm learnging the kernel, and I received a task : to redifine the action of the SIGKILL for specific process. For example, when I use the command kill -9 PID, the process of PID woudl not be killed. Then what should I do? – Xiliang Song Sep 12 '14 at 03:46
-
you need to edit your question and add tag [homework]. I'm not a kernel coder but I guess you need to modify the signal deliver code instead of only the signal handling code. – tristan Sep 12 '14 at 04:33
-
0
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

ivzeus
- 1