Linux – way to temporarily disable segfault messages in dmesg

dmesglinux-kernelsegmentation fault

Linux kernel keeps logging segfaults in ring buffer.

a.out[25415]: segfault at 8049604 ip 08049604 sp bf88e3fc error 15 in a.out[8049000+1000]

Is there a way to temporarily disable it? My usecase is that I'm running a testsuite that does all sorts of crazy things and I don't want to see segfaults in dmesg from that time period. dmesg -c is not an option because the test framework I'm forced to use is analyzing dmesg output and I cannot just clear it in the middle.

I was going through sysctl -a output if there's some kernel parameter, but I don't see anything that appears to be useful. kernel.print-fatal-signals looked promising but it's just for showing more detailed info.

Best Answer

Okay, I eventually found it. It's called debug.exception-trace.

sysctl -w debug.exception-trace=0 or echo 0 > /proc/sys/debug/exception-trace will turn it off.

# dmesg -c
# dmesg
# echo 'main;' | gcc -xc - && ./a.out
<stdin>:1:1: warning: data definition has no type or storage class
Segmentation fault
# dmesg
[  539.421736] a.out[1875]: segfault at 600874 ip 0000000000600874 sp 00007ffed85e7018 error 15 in a.out[600000+1000]
# sysctl debug.exception-trace
debug.exception-trace = 1 
# ./a.out 
Segmentation fault
# dmesg
[  539.421736] a.out[1875]: segfault at 600874 ip 0000000000600874 sp 00007ffed85e7018 error 15 in a.out[600000+1000]
[  584.492171] a.out[1878]: segfault at 600874 ip 0000000000600874 sp 00007ffc6b0d2358 error 15 in a.out[600000+1000]
# sysctl -w debug.exception-trace=0
debug.exception-trace = 0 
# ./a.out 
Segmentation fault
# dmesg
[  539.421736] a.out[1875]: segfault at 600874 ip 0000000000600874 sp 00007ffed85e7018 error 15 in a.out[600000+1000]
[  584.492171] a.out[1878]: segfault at 600874 ip 0000000000600874 sp 00007ffc6b0d2358 error 15 in a.out[600000+1000]

The last segfault is not logged.

Related Question