Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Shortest code to throw SIGILL

Background

We already have a challenge about throwing SIGSEGV, so why not a challenge about throwing SIGILL?

What is SIGILL?

SIGILL is the signal for an illegal instruction at the processor, which happens very rarely. The default action after receiving SIGILL is terminating the program and writing a core dump. The signal ID of SIGILL is 4. You encounter SIGILL very rarely, and I have absolutely no idea how to generate it in your code except via sudo kill -s 4 <pid>.

Rules

You will have root in your programs, but if you don't want to for any reasons, you may also use a normal user. I'm on a Linux computer with German locale and I do not know the English text which is displayed after catching SIGILL, but I think it's something like 'Illegal instruction'. The shortest program which throws SIGILL wins.

Answer*

Draft saved
Draft discarded
Cancel
7
  • 13
    \$\begingroup\$ −6: main(){asm("ud2");} \$\endgroup\$ Commented Nov 20, 2016 at 16:06
  • \$\begingroup\$ Also, I don't know how we count bytes for raw assembly, but 00 00 0f 0b is the machine language for ud2... \$\endgroup\$ Commented Nov 20, 2016 at 16:08
  • 6
    \$\begingroup\$ @wchargin: that's an x86 + GNU C answer. This one is portable to all GNU systems. Also note that UD2 is only 2 bytes. IDK where you got those 00 bytes; they're not part of the machine code for UD2. BTW, as I commented on Dennis's answer, there are one-byte illegal instructions in x86-64 for now, but they're not guaranteed to stay that way. \$\endgroup\$ Commented Nov 21, 2016 at 4:43
  • \$\begingroup\$ @wchargin: We count bytes for machine-code functions / programs like you'd expect. See some of my answers, like Adler32 in 32 bytes of x86-64 machine code, or GCD in 8 bytes of x86-32 machine code. \$\endgroup\$ Commented Nov 21, 2016 at 4:44
  • 2
    \$\begingroup\$ @Ruslan: They aren't; 00 00 decodes the same in x86-64 (as add [rax], al). 00 00 0f 0b would usually SIGSEGV before SIGILL, unless you happened to have a writeable pointer in rax. \$\endgroup\$ Commented Nov 24, 2016 at 9:17

AltStyle によって変換されたページ (->オリジナル) /