Ruby Fork Bomb

Was researching some interesting concepts in UNIX and came across an interesting form of DOS attack, the fork bomb.

Essentially a fork bomb infinitely loops over a command that forks a new process. In doing so you use up all the available memory on the machine. Leaving the commands here for future reference and notes on how to prevent.

In bash:

:(){ :|: & };:

In ruby:

ruby -e "loop { fork { bomb } }" &

In perl, available on mac:

perl -e "fork while fork" &

To limit the max # of user forks, edit the /etc/security/limits.conf file. It’s worth noting that ulimit -u 100 will not prevent a fork bomb, as it only sets “soft” limits.

Good references here:

Want to hire me?