Menu Home

Fork bomb

The fork bomb is a single line of code that can shut down a computer.


Raymond Lafourchette [Public domain], via Wikimedia Commons

How do you shut a computer down? Denial-of-service attacks work by using up all of a system’s resources (e.g. CPU time, memory) with useless actions, so you cannot actually do anything else. The fork bomb is perhaps the smallest denial-of-service attack.

It’s also known as a wabbit – from, I assume, Looney Tunes – and it is elegant in its simplicity. The fork does just one thing: it makes copies of itself, much like the computer worm. Those copies make copies, growing exponentially and overwhelming the system. They keep going until the computer grinds to a standstill, doing nothing but running thousands of copies of copies of copies.

Here’s an example in Bash:

bomb | bomb &

(If you don’t read Bash, the first line creates a function called “bomb,” the second line defines the function as running itself and creating a copy; the last line sets the whole thing running.)

That example uses “bomb” as the function name, but you could make it even smaller by replacing it with “:” – leaving a fork bomb that looks like a complicated emoji:

:(){ :|:& };:

Fortunately most modern systems have ways to prevent such a simple attack from overwhelming the whole system.

Categories: Computer science Sciences

The Generalist

I live in Auckland, New Zealand, and am curious about most things.

Leave a Reply