Bytes to Segfault
Challenge
Cause the currently running program to receive the SIGSEGV signal (on Linux or other *nix systems) as fast as possible. What it does with the signal doesn't matter as long as it receives it.
This is code golf, smallest answer in each language wins. Some languages will have a tougher time than others. Keep in mind that if you depend on uninitalized data, it needs to always result in a segfault; a 0.000001% chance to not work invalidates your solution.
Example program
#include <stddef.h>
#include <stdio.h>
int main() {
int* ohno = NULL;
printf("%d", *ohno);
}
C, 5 bytes ```c main; ``` …
2mo ago
[Python 2], 13 bytes …
2mo ago
Rust 1.0.0, 58 53 52 37 bytes …
2mo ago
C (compliant), 19 bytes (`g …
2mo ago
[JavaScript (Node.js)], 35 32 …
2mo ago
C, 16 bytes ```c m(){(int)m= …
2mo ago
[Bash], 11 kill -11 …
~1mo ago
7 answers
C, 5 bytes
main;
This exploits the fact that uninitialised globals live in the .bss
section, and that section is not executable. So any attempt to execute code there, regardless of content, will cause a segfault.
2 comments
Actually, I think even just main;
works (since return type defaults to int).
@Sisyphus Thanks! I'll edit my entry.
Python 2, 13 bytes
exec'+1'*5**9
No idea why this works. Something in the Python expression parser?
1 comment
How did you find this? :D
JavaScript (Node.js), 35 32 25 bytes
-7 bytes thanks to @celtschk
with(process)kill(pid,11)
1 comment
You can save 7 bytes by replacing 'SIGSEGV'
with 11
(the signal number of SIGSEGV).
C, 16 bytes
m(){*(int*)m=0;}
1 comment
I think this is kind of cheating since that online compiler declares a main() elsewhere. Otherwise you could improve it to m(){m();}
, 9 bytes, a recursive call that will eventually stack overflow with seg fault
0 comments