r/tinycode • u/AwesomeJosh • Jul 15 '11
One line Fork Bomb in Python
Nothing spectacular, but it even does some pretty funny stuff in Mac OS X with the "Resource Unavailable" OSError if you Ctrl-C:
[o.fork() for (o,i) in [(__import__('os'), __import__('itertools'))] for x in i.repeat(0)]2
1
u/abecedarius Jul 16 '11
Shorter Python (untested):
import os, itertools; [os.fork() for i in itertools.count()]2
u/AwesomeJosh Jul 16 '11
I kind of feel like compound statements are cheating, though. I guess a better description of mine would be "Single Expression" instead of "One Line"
2
u/__s Jul 17 '11 edited Jul 17 '11
You could at least take his hint and use i.count()
(edit: though arguably repeat is faster, allowing for more forking)
1
0
Jul 15 '11
[deleted]
2
u/AwesomeJosh Jul 15 '11
Yes I saw that post when Mac-O-War posted it a couple weeks ago...but this is Python.
6
29
0
6
u/digitalfreak Jul 16 '11
I prefer the swedish chef inspired one:
while(fork()) fork() ? fork() : fork()