Is there any way to cause a kernel panic under Linux? I've heard of
echo c > /proc/sysrq-trigger
but it seems to just freeze, and I'm not sure it's a kernel panic. Is there any C program I can run as root to cause a kernel panic?
Is there any way to cause a kernel panic under Linux? I've heard of
echo c > /proc/sysrq-trigger
but it seems to just freeze, and I'm not sure it's a kernel panic. Is there any C program I can run as root to cause a kernel panic?
I think you could try the following:
$ kill -6 1
This sends signal # 6 to process #1 (the init process). If you read up in the signals man page: "man 7 signals":
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)
You can find out how a process wants to handle the various signals (cat /proc/$PID/status
). See this U&L Q&A for more info: How can I check what signals a process is listening to?.
Another method is to overflow memory to induce a kernel panic. First you'll need to disable swap.
$ swapon -s
Filename Type Size Used Priority
/dev/mapper/VolGroup00-LogVol01 partition 14352376 3177812 -1
$ swapoff /dev/mapper/VolGroup00-LogVol01
Now to consume all the memory:
$ for r in /dev/ram*; do cat /dev/zero > $r; done
/proc/sysrq-trigger
. I guess you have to be in a tty to see the error information. And for the loop that consumes all memory, cat
gets a write error saying the device is full, but the kernel must take care of it, becuase if I check my RAM, only ~300MB is used.
– tkbx
Aug 02 '13 at 18:54
You can try sudo kill -SEGV 1
. This will immediately crash init as if there were MM fault(kernel equivalent of segment violation).
Some intel hardware have a NMI button (Non-maskable interrupt) that will immediately cause a panic, if you've got the NMI watchdog enabled. There are a couple other ways to cause the NMI watchdog to panic as well
CONFIG_PANIC_ON_OOPS=y
). To trigger a panic... simply load a module that callspanic()
! – Lekensteyn Aug 02 '13 at 20:49sh
as init and then typingexit
. – Jan 01 '14 at 19:44