Linux下的故意内核恐慌?

tkb*_*kbx 2 linux kernel kernel-panic

有什么办法可以在Linux下引起内核恐慌?我听说过

echo c > /proc/sysrq-trigger

但它似乎只是冻结,我不确定这是内核恐慌。有没有我可以以 root 身份运行的 C 程序来导致内核崩溃?

slm*_*slm 6

使用杀死

我认为您可以尝试以下操作:

$ kill -6 1
Run Code Online (Sandbox Code Playgroud)

这会将信号 #6 发送到进程 #1(init 进程)。如果您在信号手册页中阅读:“man 7 信号”

   Signal     Value     Action   Comment
   -------------------------------------------------------------------------
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
   SIGINT        2       Term    Interrupt from keyboard
   SIGQUIT       3       Core    Quit from keyboard
   SIGILL        4       Core    Illegal Instruction
   SIGABRT       6       Core    Abort signal from abort(3)
Run Code Online (Sandbox Code Playgroud)

您可以了解进程希望如何处理各种信号 ( cat /proc/$PID/status)。有关更多信息,请参阅此 U&L 问答:如何检查进程正在侦听哪些信号?.

溢出的记忆

另一种方法是溢出内存以引起内核恐慌。首先,您需要禁用交换。

$ swapon -s
Filename                Type        Size    Used    Priority
/dev/mapper/VolGroup00-LogVol01         partition   14352376    3177812 -1

$ swapoff /dev/mapper/VolGroup00-LogVol01
Run Code Online (Sandbox Code Playgroud)

现在消耗所有内存:

$ for r in /dev/ram*; do cat /dev/zero > $r; done
Run Code Online (Sandbox Code Playgroud)

参考

  • 实际上,PID 1 受到明确保护,不受它未设置为捕获的信号的影响。见 http://unix.stackexchange.com/questions/7441 (3认同)