Trace the Source of a SIGKILL by Adding a Kernel Logging Patch
When a Linux process is terminated by SIGKILL, the sender cannot be identified directly, but by adding a small patch to kernel/signal.c that logs the killer's PID and command name, you can trace the source of the kill, compile and flash the kernel to verify the change.
In Linux, a process killed with SIGKILL (kill -9) cannot be intercepted, ignored, or easily traced back to the sender because the signal is non‑catchable. This makes debugging unexpected terminations challenging.
Signal Definitions
The article lists the standard signal numbers defined in the kernel, such as SIGHUP 1, SIGINT 2, up to SIGUSR2 31. These definitions provide context for understanding where SIGKILL 9 fits among other signals.
Kernel Patch to Log SIGKILL Sender
To identify which process sent a SIGKILL, modify the kernel source file kernel/signal.c in the function kill_something_info(). Insert the following code snippet:
if (sig == SIGKILL) {
struct task_struct *t = current;
printk(KERN_WARNING "SIGKILL sent by PID:%d (%s) to PID:%d
", t->pid, t->comm, pid);
}This code captures the current task (the killer), prints a warning with its PID and command name, and the target PID.
Build and Deploy
After applying the patch, recompile the kernel and flash it to the target device. Once the new kernel runs, any SIGKILL will generate a kernel warning message showing the sender’s PID and process name, confirming that the modification works.
Conclusion
Although SIGKILL is designed to be unstoppable and untraceable, a small kernel modification enables administrators to log the origin of such kills, aiding in debugging and system reliability.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
