A fork bomb is a malicious program designed to create an excessive number of processes on a computer system, leading to resource exhaustion and potentially a system crash or unresponsiveness[2][3][4]. While commonly associated with Unix-like systems and the fork() system call, a similar effect can be achieved on Windows by repeatedly launching new instances of a program or script [1, 5][3].
It's important to understand that creating and running a fork bomb can cause significant harm to a computer system[1][2][8]. This information is provided for educational purposes only, to explain the concept, and should only be attempted in a controlled, isolated environment like a virtual machine. Do not run this on your personal computer or any system you do not own or have explicit permission to test on. Running a fork bomb can lead to data loss and system instability [4, 6, 10].
On Windows, a simple way to create a fork bomb is using a batch script[3][4]. A batch file is a script that the Windows command interpreter (cmd.exe) can execute.
Here's how a simple batch file fork bomb works:
- Self-replication: The core idea is to create a script that launches new copies of itself repeatedly.
- Infinite loop: This replication happens within an infinite loop to ensure exponential growth in the number of processes[3].
A basic example of a batch file that can act as a simple fork bomb is:
%0|%0
Let's break down this command:
%0 in a batch file refers to the name of the batch file itself [12].
| is the pipe operator, which is typically used to send the output of one command as the input to another [12][7]. In the context of this fork bomb, it helps to create multiple processes. When used this way in a batch file, Windows creates a new process for each side of the pipe [12][7].
When this batch file is executed, it attempts to run itself (%0) and pipe its (non-existent) output to another instance of itself (%0). This action causes Windows to launch two new processes of the same batch file [12]. Each of those new processes then does the same, leading to an exponential increase in the number of running cmd.exe processes, quickly overwhelming the system's resources [1, 12].
Another simple batch file example is:
@echo off
:start
start %0
goto start
Explanation:
@echo off prevents the commands from being displayed in the command prompt window.
:start defines a label named "start".
start %0 launches a new instance of the current batch file (%0) in a new window.
goto start directs the execution back to the "start" label, creating an infinite loop [2].
This script continuously launches new command prompt windows, each running another copy of the script, resulting in a rapid depletion of system resources [2].
How it works in essence:
Unlike Unix-like systems where fork() creates a near-identical copy of a process, Windows requires explicitly starting a new process [1]. These simple batch file examples achieve a similar outcome by repeatedly using commands like start or leveraging the behavior of the pipe operator (|) with %0 to launch new instances of the script [1, 12]. Each new instance consumes system resources like CPU time and entries in the process table, eventually leading to a denial of service [1, 5, 11][8].
Important Considerations and Warnings:
- System Instability: Running a fork bomb can make your system unstable, unresponsive, or even crash it [4, 6, 10].
- Resource Exhaustion: It consumes significant CPU and memory resources [1, 11][7].
- Difficulty in Termination: Once started, a fork bomb can be very difficult to stop without potentially losing unsaved work or requiring a system reboot [4, 9].
- Ethical Implications: Creating and deploying fork bombs without permission is unethical and potentially illegal [10].
If you are interested in understanding fork bombs, it is highly recommended to study the code and the concept in a safe environment like a virtual machine where any potential damage is contained [10, 13].