Linux – What’s the history behind the fork bomb

cpuforkhistorylinux

I have read the other questions about its functionality — that fork bombs operate both by consuming CPU time in the process of forking, and by saturating the operating system's process table.

A basic implementation of a fork bomb is an infinite loop that repeatedly launches the same processes.

But I really want to know: what's the story of this command? why this :(){ :|:& };: and not another one?

Best Answer

It is not something new. It dates way back to 1970's when it got introduced.

Quoting from here,

One of the earliest accounts of a fork bomb was at the University of Washington on a Burroughs 5500 in 1969. It is described as a "hack" named RABBITS that would make two copies of itself when it was run, and these two would generate two more copies each, and the copies would continue making more copies until memory was full, causing a system crash. Q The Misanthrope wrote a Rabbit-like program using BASIC in 1972 while in grade 7. Jerry Leichter of Yale University describes hearing of programs similar to rabbits or fork bombs at his Alma Mater of Princeton and says given his graduation date, they must be from 1973 or earlier. An account dating to 1974 describes a program actually named "rabbit" running on an IBM 360 system at a large firm and a young employee who was discharged for running it.

So the :(){ :|:& };: is just a way of implementing the fork bomb in shell. If you take some other programming language, you could implement in those languages as well. For instance, in python you could implement the fork bomb as,

 import os
 while True: 
 os.fork()

More ways of implementing the fork bomb in different languages can be found from the wikipedia link.

If you want to understand the syntax, it is pretty simple. A normal function in shell would look like,

foo(){
 arg1=$1
 arg2=$2
 echo 'Bar..'
 #do_something on $arg argument
}

fork() bomb is defined as follows:

:(){
 :|:&
};:
:|:

:|: - Next it will call itself using programming technique called recursion and pipes the output to another call of the function :. The worst part is function get called two times to bomb your system.

& - Puts the function call in the background so child cannot die at all and start eating system resources.

; - Terminate the function definition

: - Call (run) the function aka set the fork() bomb.

Here is more human readable code:

bomb() {
 bomb | bomb &
}; bomb

References

http://www.cyberciti.biz/faq/understanding-bash-fork-bomb/