The Cutest Littlest Forkbomb

February 24, 2015

In one of his last tweets @levans posted the cutest Rust-lang fork bomb:

fn main(){std::thread::spawn(main);main()}

at 42 characters longs, which he sees like a sign. Excluding headers, you can do even shorter in C++:

main(){boost::thread x(main);main();}

It’s not really a terrifying forkbomb (as Linux, for e.g., kills everything after a while because processes run out of memory), and we could have done much worse with a process-level (rather than a thread-level) forkbomb:

main() { fork(); main(); }

This variant creates separate processes… none of which individualy can exhaust its memory! Don’t try this one on your main box (but it could be fun in a virtual machine).

bobomb