fork-bomb
fork-bomb copied to clipboard
Ruby example isn't good
The Ruby example loops and forks... I don't think it's a fork bomb at all.
A fork bomb in Ruby 3 will look like this:
#!/usr/bin/env -S ruby --disable-gems
method(def f = fork { f && sleep }).call
There's no loop inside. The method f
calls itself. It requires no file load, no loop.
Modified version for Ruby 3 only:
#!/usr/bin/env -S ruby --disable-gems
send(def f = fork { f && sleep })
For lower Ruby versions, we can use stabby lambda, lambda or a proc:
#!/usr/bin/env -S ruby --disable-gems
(f = -> { fork { f.() && sleep } }).()