The Art in Code

Snippets of famous, interesting, historically relevant or thought-provoking... code.

Website maintained by Filip Stanis Based on theme by mattgraham

005 - Fork bomb

Code snippet of a fork bomb in Python

Snippet source

A fork bomb is a type of attack where a process makes copies of itself until the system runs out of resources.

The code above shows this type of attack implemented in Python in just 3 lines of code. An infinite loop calls fork(), a system call that causes the process to make a copy of itself. The newly created process then proceeds to do the same thing once it starts.

Note: Running this code will almost certainly cause your system to hang and you may be forced to reboot.

Due to its malicious nature, the fork bomb can be considered to be one of the simplest possible computer viruses.